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

binfmt/elf_loadfile: Set sh_addr even if SHF_ALLOC == 0 #270

Merged
merged 1 commit into from
Aug 16, 2024

Conversation

pussuw
Copy link

@pussuw pussuw commented Aug 16, 2024

Set sh_addr for regions that are not allocated. Some relocations might depend on this.

The fault in my case occurs when setting CONFIG_HAVE_CXX=y. In this case, the .ctor and .dtor sections do not get allocated, but the crt code depends on linker defined symbols _sctors/_ectors etc. These generate PC relative relocations and thus, the .ctor and .dtor output sections need an output VMA even though nothing is there. Otherwise the relocations will point to god knows where (in my case to address 0).

The problem results in full system crash later:
elf_symvalue: Other: 00000000+00000001=00000001
up_relocateadd: PCREL_HI20 at c00002dc [00000417] to sym=0x80409e80 st_value=1 _calc_imm: offset=-3221226203: hi=-786432 lo=-731
up_relocateadd: ERROR: PCREL_HI20 at c00002dc bad:ffffffff40000000 elf_relocateadd: ERROR: Section 2 reloc 52: Relocation failed: -22

The RISC-V elf64 linker does not like the uninitialized PC relative relocation entries, as the relocation offset cannot be reached with with the RV64 instruction set.

More about this issue can be found here:
apache#11322

Set sh_addr for regions that are not allocated. Some relocations might
depend on this.

The fault in my case occurs when setting CONFIG_HAVE_CXX=y. In this case,
the .ctor and .dtor sections do not get allocated, but the crt code
depends on linker defined symbols _sctors/_ectors etc. These generate PC
relative relocations and thus, the .ctor and .dtor output sections need
an output VMA even though nothing is there. Otherwise the relocations will
point to god knows where (in my case to address 0).

The problem results in full system crash later:
elf_symvalue: Other: 00000000+00000001=00000001
up_relocateadd: PCREL_HI20 at c00002dc [00000417] to sym=0x80409e80 st_value=1
_calc_imm: offset=-3221226203: hi=-786432 lo=-731
up_relocateadd: ERROR: PCREL_HI20 at c00002dc bad:ffffffff40000000
elf_relocateadd: ERROR: Section 2 reloc 52: Relocation failed: -22

The RISC-V elf64 linker does not like the uninitialized PC relative
relocation entries, as the relocation offset cannot be reached with
with the RV64 instruction set.

More about this issue can be found here:
apache#11322
@pussuw pussuw merged commit 16f1d8c into master Aug 16, 2024
11 checks passed
@pussuw pussuw deleted the fix_elf_loader branch August 16, 2024 09:20
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.

1 participant