ld seems to disregard section relative specifiers on symbols
Jan Beulich
jbeulich@suse.com
Mon Sep 9 08:22:26 GMT 2024
On 07.09.2024 07:27, Julian Waters wrote:
> Thanks for looking into this! I think I can also provide further strange
> differences compared to clang. If the code above is compiled by gcc to an
> object file, disassembling the file will yield a secrel attribute with a
> value of .tls$, while disassembling a clang compiled object file will yield
> the attribute with the local symbol:
>
> Compiled by gcc (Meaning it was assembled by as):
> 0000000000000000 <sectionrelative>:
> 0: b8 00 00 00 00 mov eax,0x0
> 1: IMAGE_REL_AMD64_SECREL .tls$
> 5: c3 ret
>
> Compiled by clang (Meaning it was assembled by the clang integrated
> assembler):
> 0000000000000000 <sectionrelative>:
> 0: b8 00 00 00 00 mov eax,0x0
> 1: IMAGE_REL_AMD64_SECREL local
> 5: c3 ret
> 6: 66 2e 0f 1f 84 00 00 cs nop WORD PTR [rax+rax*1+0x0]
> d: 00 00 00
>
> The IMAGE_REL_AMD64_SECREL entries are different in the 2 disassembly
> snippets above (cs nop WORD PTR in clang can probably be ignored).
That's a difference in how relocs are generated. When symbols can't be
overridden (except for weak symbols I think that's a concept COFF/PE
doesn't know), it wouldn't normally matter whether the reloc targets
the symbol itself or the section/offset where the symbol lives. Without
knowing how Clang behaves I did notice the behavior as one potential
source of the problem you reported, but I'm meanwhile relatively
certain it's unrelated. Whether it's a problem for other reasons I
can't tell (yet).
> However
> this difference seems to not be the reason that the linked programs produce
> different results, as assembling with as and then linking with clang still
> gives the correct result of 8
Right. And anyway - one thing at a time please.
Jan
More information about the Binutils
mailing list