Repository navigation
feat(elf): place __global_pointer$ at .sdata + 0x800 - #3027
Conversation
|
I'm unsure how essential it is for us to exactly match BFD's formula for this symbol. LLD seems to use a simpler formulation. One thing I did just notice, looking at the pre-existing code for this symbol is that the address in symtab is inconsistent with the value used by relocations which reference the symbol. edit: Your change appears to fix this, which is good, but it's possible that fix should be separate from changes to the formula used. |
|
Thanks for the quick reply, I can split the symtab/relocation fix into a separate PR and adjust this one to follow the simpler LLD formula for placing |
|
Thanks, that sounds good. |
baa98e2 to
ca1d233
Compare
__global_pointer$ using GNU ld's formula__global_pointer$ using LLD's formula
|
I've switched There are two CI failures I'm not sure how I should handle:
|
|
Regarding dealing with the empty .sdata section, perhaps #3068 will help? |
a884ad5 to
c7ecd09
Compare
|
Hey David, that was the fix, thank you so much! I've synced the PR with the current main and the aarch64 CI tests now pass. One thing to note: I also added in the diff-ignore from my previous message as a separate commit on top. With this commit all of the CI tests now pass. I just want to confirm if this is the direction you see wild going for that case, since I don't want to change what linker-diff ignores without a clear go ahead. If you'd rather handle it differently, I'm happy to revert that commit and take another approach. |
davidlattimore
left a comment
There was a problem hiding this comment.
Give how variable the section into which the symbol gets placed is, I think adding the diff-ignore as you've done is reasonble.
| // Like LLD, a section-offset symbol (e.g. RISC-V's __global_pointer$) whose section has no | ||
| // content is placed relative to the file header instead, so that it doesn't force an empty | ||
| // section to be emitted. | ||
| for definition in &mut self.internal_symbols.symbol_definitions { |
There was a problem hiding this comment.
I'm not sure about doing this here. It introduces a side-effect to determine_kept_sections. Also, the code here doesn't take into account secondary sections. I think both problems can be solved together. If you moved this code to a separate function that was run after determine_kept_sections returns, then it'd automatically end up taking secondary sections into account, since the code below keeps the primary section if one of its secondary sections is kept would already have run. You might need to change the loop immediately below this one so that SymbolPlacement::SectionStartOffset doesn't cause a symbol to be kept.
There was a problem hiding this comment.
Sounds good, will update here shortly.
There was a problem hiding this comment.
Added a second function running right after determine_kept_sections for relocating symbols in sections not kept to the file header. Also updated the loop in determine_kept_sections to ignore SymbolPlacement::SectionStartOffset.
__global_pointer$ using LLD's formula__global_pointer$ at .sdata + 0x800
In this PR the
__global_pointer$is moved from the start of.datato using the formula from LLD's default script:To do this, new sections had to be inserted between
.dataand.bss, namely.sdataand.sbss. These new sections also impact the output sections of all supported ELF architecture, including RISCV.Known issue:
linker-script-region-lmafails onaarch64. This is due to the new.sdataand.sbssmoving.bssover to another segment, crossing the test file size limit. Open to suggestions on skipping empty.sdata/.sbssthere vs. limiting them to RISC-V.Related to #2520:
gpneeds to be in the right place before relaxation work can start. Opening this PR to check if GNU ld's approach is the direction planned for wild; happy to change it if not.