This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Linkerscript: support combination of linkerscript and --compress-debug-sections.
ClosedPublic

Authored by grimar on Apr 20 2017, 5:23 AM.

Details

Reviewers
ruiu
rafael
Summary

Previously it was impossible to use linkerscript with --compress-debug-sections because of
assert failture:
Assertion failed: isFinalized(), file C:\access_softek\llvm\lib\MC\StringTableBuilder.cpp, line 64

Patch fixes the issue.

Diff Detail

Event Timeline

grimar created this revision.Apr 20 2017, 5:23 AM
ruiu added inline comments.Apr 24 2017, 10:48 AM
test/ELF/linkerscript/compress-debug-sections.s
7

What is the point of such linker script? I wonder why do you want to control the layout of .debug_str section.

19–21

nit: Can you reduce number of repetitions of A, B, C and D? Just a few characters should suffice.

grimar added inline comments.Apr 25 2017, 3:27 AM
test/ELF/linkerscript/compress-debug-sections.s
7

Its just a sample script reduced from script of FreeBSD kernel:
https://svnweb.freebsd.org/base/head/sys/conf/ldscript.amd64?revision=315522&view=markup#l223
I do not think they really want to control layout.

Probably for this testcase I really could use just empty script and let debug section to be orphan. I'll check it when will update this patch.

19–21

Interesting that doing that revealed an issue. After reducing amount of repetitions I ended up with broken sections size or errors during decompression.
That happens because void LinkerScript::process(BaseCommand &Base) calculates size of output section wrong when doing output(). It takes each input section and updates size of output section, what works wrong for compressed case.
It's just a luck that testcase "worked" before.

I'll try to find how to fix this properly.

grimar updated this revision to Diff 97418.May 2 2017, 3:34 AM
  • Addressed comments.
  • Improved testcase to show that woth mergeable and non-mergeable cases work fine.
grimar updated this revision to Diff 97453.May 2 2017, 8:04 AM
  • Addressed review comments.
grimar updated this revision to Diff 97454.May 2 2017, 8:06 AM
  • Fixed mistype in comment.
ruiu added inline comments.May 2 2017, 3:27 PM
ELF/OutputSections.cpp
154

during -> by

test/ELF/linkerscript/compress-debug-sections.s
16

I don't think you really need this much hand-crafted debug info. You can just create an object file with -g, link it with LLD and verify that the debug section doesn't have SHF_COMPRESSED flag by using llvm-objdump or readobj.

grimar added inline comments.May 3 2017, 12:52 AM
test/ELF/linkerscript/compress-debug-sections.s
16

But that will not cover things this patch implements.
I believe we still want to check that compressing - decompressing flow producing the same results in scripted case. When you asked in previous diff to reduce amount of repitions of A, B, C, D, that revealed an issue in calculating output section size, what produced broken zlib stream, I think it is worth to check that this case works now. Just checking the flag would not reveal it.

I think it is probably not important to check how mergeable synthetic compressed section works. I believe I can significantly simplify the testcase to use .debug_str only with merging disabled. Let me try.

grimar updated this revision to Diff 97572.May 3 2017, 2:00 AM
  • Simplified testcase.
grimar updated this revision to Diff 97573.May 3 2017, 2:01 AM
  • Fix testcase requirements.
ELF/OutputSections.cpp
154

Done.

ruiu added inline comments.May 3 2017, 2:21 AM
test/ELF/linkerscript/compress-debug-sections.s
18

I don't think you are actually testing the new code. Please use llvm-objdump or llvm-readelf to verify that debug sections don't SHT_COMPRESSED if linker scripts are in use. You don't need to use llvm-dwarfdump as the contents doesn't matter.

grimar added inline comments.May 3 2017, 2:28 AM
test/ELF/linkerscript/compress-debug-sections.s
18

Please use llvm-objdump or llvm-readelf to verify that debug sections don't SHT_COMPRESSED if linker scripts are in use.

I think I got what you want to say. Both your comments saying these sections don't compressed. But them are ! We do not support custom layout for them, but compression itself is supported by this patch. That is why I am doing that checks because content matters, as I check that them can be compressed and then decompressed and the content remains the same.

grimar updated this revision to Diff 97803.May 4 2017, 3:30 AM
  • Added check that shows we do compression of debug sections if linker script was used.
ruiu accepted this revision.May 5 2017, 12:36 PM

LGTM

This revision is now accepted and ready to land.May 5 2017, 12:36 PM
grimar closed this revision.May 8 2017, 3:35 AM

r302413