This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Add testcase documenting flags assigned when empty synthetic section is removed.
ClosedPublic

Authored by grimar on Feb 22 2018, 9:49 AM.

Details

Summary

This responds to PR36475,

r325763 led to unexprected layout change, though
new behavior seems to be more correct.

Previously we could have following script:

.foo : { *(.foo) } 
.bar : { *(.synthetic_empty) BYTE(0x11) }}

where synthetic_empty is a synthetic section which is empty and
hence removed by linker.
Before r325763 .bar would receive section flags from .synthetic_empty,
but after this revision it receives flags the same as .foo section has.

It is the same as if there would not be any synthetic_empty section in a script,
so looks reasonable and consistent behavior:

.foo : { *(.foo) } 
.bar : { BYTE(0x11) }}

Patch adds testcase to document it.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Feb 22 2018, 9:49 AM
ruiu accepted this revision.Feb 22 2018, 5:52 PM

LGTM with this fix.

test/ELF/linkerscript/empty-synthetic-removed-flags.s
3–5 ↗(On Diff #135447)

For multi-line linker script, can you avoid using \ for line continuation? I found that that is hard to debug when something goes wrong, because this "echo" ends up with a very long single line with a lot of whitespace characters, and "^" marker doesn't make sense in such output because lines are wrapped around.

You could instead write

echo "SECTIONS { .foo : { *(.foo) }" > %t.script
echo "           .bar : { *(.got.plt) BYTE(0x11) }}" >> %t.script

That said, since this example is short, the best way of doing it is to write it in one line.

echo "SECTIONS { .foo : { *(.foo) } .bar : { *(.got.plt) BYTE(0x11) }}" > %t.script
25–27 ↗(On Diff #135447)

Ditto

This revision is now accepted and ready to land.Feb 22 2018, 5:52 PM
This revision was automatically updated to reflect the committed changes.