[PATCH] bfd/ELF: don't lose trailing globals from SHF_MERGE sections

Jan Beulich jbeulich@suse.com
Tue Oct 7 12:27:42 GMT 2025


On 07.10.2025 14:13, Michael Matz wrote:
> Hello,
> 
> On Tue, 7 Oct 2025, Jan Beulich wrote:
> 
>>>> I actually wonder whether we shouldn't also respect offset > sec->rawsize,
>>>> by adding offset - sec->rawsize to the return value.
>>>>
>>>> If, for whatever reason, this adjustment was unacceptable, the SEC_EXCLUDE
>>>> check in elf_link_output_extsym() may want extending to also look for
>>>> SEC_KEEP, which replaced sections will have set (afaict).
>>>
>>> Have you found testcases taking that code path?
>>
>> Yes (if "testcases" isn't meant to be limited to what is in the tree 
>> right now),
> 
> Then consider me fairly interested :)  Anything I can try myself?
> 
>> and that other change was in fact the fix I had first tried. 
>> Having thought of the (posted) alternative, I considered that the 
>> hopefully more "clean" approach.
> 
> As said, I think it makes sense, but I'd love to watch it in action.

I hope the two attached files still represent the original code I observed
this with. I have been keeping altering them as I was working on a bigger
series making section merging work when linking ELF objects into PE binaries.
While doing that work I was merely trying to use pure ELF linking as
"reference". Just to find an issue there ...

Jan
-------------- next part --------------
# assemble this and str2.s, then
# (a) ld --oformat=elf32-i386 -shared -o tmp/todo/str{.so,1.o,2.o}
# (b) ld -mi386pep --subsystem=10 --dynamicbase -o tmp/todo/str{.efi,1.o,2.o}

	.file "str1.s"

	.section .rodata.str1, "aMS", @progbits, 1
	.asciz "abc"
	.global def
def:
	.asciz "def"
ghijk:
	.asciz "ghijk"
	.asciz "lmn"
	.asciz "opqrst"
	.asciz "uvw"
	.asciz "xyz"
	.global tail1
tail1:

	.section .data.rel.ro, "aw", @progbits
	.dc.a def
	.dc.a ghijk + 2
	.dc.a tail1, tail2
-------------- next part --------------
	.file "str2.s"

	.section .rodata.str1, "aMS", @progbits, 1
	.asciz "xyz"
	.asciz "uvw"
	.asciz "opqrst"
	.asciz "lmn"
ijk:
	.asciz "ijk"
	.global defgh
defgh:
	.asciz "defgh"
	.asciz "abc"
$12345:
	.asciz "12345"
	.global tail2
tail2:

	.section .data.rel.ro, "aw", @progbits
	.dc.a defgh + 2
	.dc.a ijk
	.dc.a tail1, tail2


More information about the Binutils mailing list