Open Quuxplusone opened 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.
Sure, put your diff up and I'll have a look at it :)
done! It now lives at https://reviews.llvm.org/D104346
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?
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
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?
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
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.)
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.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.
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.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.