This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Allow merging of strings sections for -relocatable output.
AbandonedPublic

Authored by grimar on Nov 13 2017, 8:21 AM.

Details

Reviewers
ruiu
rafael
Summary

This is PR35223.

r317406 stopped merging SHF_MERGE sections when -r is given.
Previously we used Alignment, Flags and section Name together to
generate a complex key for merging sections. For -r case all 3 were used,
but for regular case we merged sections by name only for a long time
and r317406 changed behavior to merge sections by name for all outputs,
that allowed to simplify code and sped up linker a bit.

But above broke -relocatable output in sence that tools like dwarfdump (both gnu
and llvm one) expects to see single .debug_str section in output.
After the r317406 we started producing unique output section for each input
and tools are upset.

I suggest to allow relocatable output to merge SHF_MERGE strings sections.
In case when input sections has different sh_entsize, I think we can just drop
the SHF_MERGE flag and merge them. That looks consistent with what ld.bfd
do and should not be an issue, because I believe normally string sections
always have sh_entsize = 1. llvm-mc even ignores any values explicitly set for .debug_str
sh_entsize and renders 1 to output, though gas allows different values.

Diff Detail

Event Timeline

grimar created this revision.Nov 13 2017, 8:21 AM

Given that the issue with not combining sections was purely restricted to .debug_str, which only ever has an entsize of 1, would it not make more sense to not combine the InputSections for different entsize values?

I'm wary about removing the SHF_MERGE flag, because I'm pretty sure mergeable sections of different sizes are not that rare, although they do not typically have the same name, so maybe it's okay.

grimar abandoned this revision.Nov 17 2017, 3:46 AM

Abandoning. Another approach was chosen (D40026) and landed (r318516 + r318518)