Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Finish / clean up MapFile implementation #49658

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR50689
Status NEW
Importance P enhancement
Reported by Jez Ng (jezreel@gmail.com)
Reported on 2021-06-11 18:07:02 -0700
Last modified on 2021-11-16 15:06:44 -0800
Version unspecified
Hardware PC All
CC gkm@fb.com, jezreel@gmail.com, leevince@fb.com, llvm-bugs@lists.llvm.org, nicolasweber@gmx.de, rgr@fb.com, smeenai@fb.com, th3charlie@gmail.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

These are probably good tasks for someone looking to get familiarized with the LLD codebase, since the mapfile isn't critical to what we are working on at the moment. (Please ping me first before starting on these.)

  1. Dump dead-stripped symbols, as per this TODO: https://github.com/llvm/llvm-project/blob/main/lld/MachO/MapFile.cpp#L153. Essentially, symbols for which isLive() returns false.

  2. getSectionSyms() puts all the symbols into a map of section -> symbols, but this seems unnecessary. This was likely copied from the ELF port, which prints a section header before the list of symbols it contains. But the Mach-O map file doesn't print these headers.

  3. Parallelize the symbol sort. We can use LLVM's parallel_sort for this. If two symbols have the same address, we can use their symbol name to tie-break; the end result should be deterministic.

  4. Dump the cstring / fixed-width literals (from CStringInputSection and WordLiteralInputSection respectively) into the map file.

To see the expected map file output, download the tar attachment from https://bugs.llvm.org/show_bug.cgi?id=48657. Unpack and link it like so: ld -map mapfile @response.txt. This will generate a "mapfile" file in the CWD. This mapfile will contain examples dead symbols and literals (grep for "literal string" in the file).

That said, this file is pretty large (since Chromium is pretty large), so you may want to construct smaller test programs for a better understanding.

Quuxplusone commented 3 years ago

Hi Jez! I want to work on No.3 and I've done implementation locally, though I am not sure if the current test case is sufficient. If you are Ok with it, I can send a patch with my code changes and we can discuss what kind of test case we need.

Quuxplusone commented 3 years ago

Sure, put your diff up and I'll have a look at it :)

Quuxplusone commented 3 years ago

done! It now lives at https://reviews.llvm.org/D104346

Quuxplusone commented 3 years ago

Hi Jez! As for the first TODO item, are we going to dump dead-stripped symbols blindly or there's a need to check some kind of CLI commands?

Quuxplusone commented 3 years ago

I think we can just always dump the dead-stripped symbols. I would check ld64's output to make sure we match, but I'm not aware of any CLI options that would affect this behavior

Quuxplusone commented 3 years ago

I find this in the test-suite: https://github.com/llvm/llvm-project/blob/eb237ffca821839374574b2195c865765ebf5d09/lld/test/MachO/dead-strip.s#L10

Does this imply that we should not output any dead stripped symbols when having the -dead_stirp option?

Quuxplusone commented 3 years ago
They shouldn't be in the "normal" output but in a separate section at the end:

% cat test.c
void dead() {}
int main() {}
% clang test.c -Wl,-map,test.txt -Wl,-dead_strip
% cat test.txt
# Path: a.out
# Arch: x86_64
# Object files:
[  0] linker synthesized
[  1] /var/folders/qt/hxckwtm545l643cnk200wzt00000gn/T/test-18287b.o
# Sections:
# Address   Size        Segment Section
0x100003FB0 0x00000008  __TEXT  __text
0x100003FB8 0x00000048  __TEXT  __unwind_info
# Symbols:
# Address   Size        File  Name
0x100003FB0 0x00000008  [  1] _main
0x100003FB8 0x00000048  [  0] compact unwind info

# Dead Stripped Symbols:
#           Size        File  Name
<<dead>>    0x00000010  [  1] _dead
<<dead>>    0x00000018  [  1] CIE