Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: unify load on NOMMU #611

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

badochov
Copy link
Contributor

@badochov badochov commented Oct 22, 2024

JIRA: RTOS-958

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: sparc-mimas, armv8r

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@badochov badochov marked this pull request as draft October 22, 2024 11:07
proc/process.c Outdated Show resolved Hide resolved
@badochov badochov force-pushed the badochov/process_load_remove_ifdef branch from ff1ed8d to 2a6dd63 Compare October 22, 2024 11:09
@badochov badochov marked this pull request as ready for review October 22, 2024 11:19
Copy link

github-actions bot commented Oct 22, 2024

Unit Test Results

7 787 tests  ±0   7 069 ✅ ±0   41m 1s ⏱️ -5s
  461 suites ±0     718 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 58dceed. ± Comparison against base commit a6de825.

♻️ This comment has been updated with latest results.

proc/process.c Outdated
Comment on lines 914 to 917
sym = (Elf32_Sym *)(symTab + (ELF32_R_SYM(rela->r_info) * sizeof(Elf32_Sym)));

/* Write addend to the address */
*(char **)relptr = (char *)(sym->st_value + rela->r_addend);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty much the only difference between SPARC and ARM stuff. Perhaps we could store strcmp result and use it here to do this operation conditionally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it and it was a bunny hole.

Each architecture has a separate set of Relocation Types, however relocation types are just numbers and there maybe a clash eg. R_SPARC_32 on SPARC and R_ARM_REL32(unused now) on ARM have the same value of 3. Thus, we should compare relocation type separately on each architecture. This can be done either via ifdefs or via checking if in the ELF header the machine type(e_machine field). Now this clash will not happen, as SPARC uses RELA and ARM uses REL. If we unify the code there is high potential for a bug in the future if more relocation types would be needed for some reason.

In my opinion the code should be modified so that:

  1. Getting rela section on an architecture using rel would result in ENOEXEC and vice versa
  2. We should have separate relocations handler for each architecture

What do you think about it? Also, Should we check the architecture via ifdef or the ELF HEADER?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, first question that has to be asked is if we'll ever need to handle any more relocation types in the kernel? Aren't dynamic linker solely in the userspace?

Regarding collisions of values of relocation types between archs - this can be solved by e.g. defining our own, abstract, machine independent relocation types on per arch basis, and handle these instead of e.g. R_SPARC_32 directly (that might be represented by e.g. HAL_R_REL32 or something along these lines).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. To support static FDPIC program some 2 more relocations are needed, unless we want to move relocation process to the userspace.

Additionally if we ever want to handle C++ on NOMMU then to have proper exceptions handling there may be a need to add few more relocations. However that's a harder topic as currently exception handling causes relocations in text segment ☠️

  1. Nice idea!

Also my bad, both ARM and SPARC support in ABI both rela and rel, however GCC by default uses only one of those types if possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My perspective is as follows - better for this code to do the thing it has to do nice and simple and to not prepare for the future that might never come (kinda a part of the top-down philosophy).

From my side - the proposed version is way better and status quo as is, so I have no objection to merge if you wish to not make any further changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked and compilation with -static-pie fixes issue of relocation in text segment in exceptions handling section

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have adapted code to you suggestions, and added feature to handle both Rel and Rela relocations on both targets

proc/process.c Outdated Show resolved Hide resolved
@badochov badochov force-pushed the badochov/process_load_remove_ifdef branch 2 times, most recently from 172480e to 58dceed Compare October 22, 2024 15:55
agkaminski
agkaminski previously approved these changes Oct 23, 2024
hal/armv7m/arch/elf.h Outdated Show resolved Hide resolved
hal/armv7m/arch/elf.h Outdated Show resolved Hide resolved
hal/sparcv8leon3/arch/elf.h Outdated Show resolved Hide resolved
hal/sparcv8leon3/arch/elf.h Outdated Show resolved Hide resolved
@badochov badochov force-pushed the badochov/process_load_remove_ifdef branch from e448443 to 55f8566 Compare October 23, 2024 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants