Implement command-line options -map
Details
- Reviewers
int3 thakis - Group Reviewers
Restricted Project - Commits
- rGed8bff13dcaa: [lld-macho] implement options -map
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks for the patch!
Overall, looks pretty good.
Please clang-format the file (make the comments in the first few lines <= 80 cls first).
Please add a test.
Does ld64 print CommonSymbols, or does this run late enough that they've already been replaced by Defineds? (A good thing to include in the test.)
lld/MachO doesn't use TimeTraceScope anywhere else yet (it should!), so it's a bit weird to have it here. Maybe should add actual time trace support in a patch before this? But I suppose that part is fine as-is as well.
The format fixed. Yes, CommonSymbols have already been replaced by Defineds.
Could we merge this patch first, and then I add test? I am not familiar with writing tests yet, it may take some time.
New code should be covered by a test added in the same change. See https://llvm.org/docs/TestingGuide.html#writing-new-regression-tests and https://llvm.org/docs/CommandGuide/FileCheck.html#tutorial -- and look at the existing tests in lld/test/MachO for many examples, of course :)
Yeah diffs should generally come with corresponding tests. This code is fairly self-contained, so there's little chance of rebase conflicts and no rush to land :)
You can run the existing tests under lld/macho via llvm-lit -vva <filename>. -vva will let you see what commands are being run to get a sense of how things work.
lld/MachO/MapFile.cpp | ||
---|---|---|
10 | ||
62–71 | this is fairly similar to SymtabSection::finalizeContents, with some minor differences. We should check if the logic can be factored out. I can help with that though :) could you leave a TODO for now? | |
66 | we should check for sym != nullptr in this loop (we don't parse symbols in debug sections, so they will be null) also JFYI, lld::macho:: won't be necessary once D98149 lands | |
74–75 | this function isn't using parallel-for :) leave a TODO? | |
85 | llvm/TextAPI/MachO/Architecture.h defines getArchitectureName() |
lld/MachO/Writer.cpp | ||
---|---|---|
939 | I think writeMapFile() should be moved below this line -- there's no need to emit the mapfile if we can't emit the binary itself | |
lld/test/MachO/map-file.s | ||
7 | The test seems to be failing, I guess it should be a -map without the =? also I think it would be nicer to have the output go to %t/map | |
15 | we should test common symbols (.comm) as well, as @thakis mentioned in an earlier comment | |
29–30 | We try not to match against hardcoded addresses because they're a bit of a pain to update. In this case I think it would be better to match this against llvm-objdump's output: something like RUN: llvm-objdump --syms --section-headers %t/test-map > %t/objdump RUN: cat %t/objdump %t/map > %t/out RUN: FileCheck %s < %t/out Then we can use numeric substitutions to check that the values line up. |
lld/test/MachO/map-file.s | ||
---|---|---|
29–30 | So right now the test is just ignoring the value, but it would be better if it checked that it matched the actual addresses in the binary using numeric substitutions. It would be something like this: # RUN: llvm-objdump --syms --section-headers %t/test-map > %t/objdump # RUN: cat %t/objdump %t/map > %t/out # RUN: FileCheck %s < %t/out ... # CHECK: Sections: # CHECK-NEXT: Idx Name Size VMA Type # CHECK-NEXT: 0 __text {{[0-9a-f]+}} [[#%x,TEXT:]] TEXT ... # CHECK-NEXT: # Sections: # CHECK-NEXT: # Address Size Segment Section # CHECK-NEXT: 0x[[#TEXT]] 0x00000001 __TEXT __text |
lld/test/MachO/map-file.s | ||
---|---|---|
31–33 | you're re-defining the TEXT/BSS/DATA symbols here (which were already defined on lines 25-27). I know they're the same values since these symbols are at the beginnings of their sections, but I think it would be nicer to define separate names for the symbols (e.g. MAIN, NUMBER, FOO). |
lld/MachO/Driver.cpp | ||
---|---|---|
829 | maybe check and warn if the path is empty? |
lld/MachO/Driver.cpp | ||
---|---|---|
829 | The empty check is already done in writeMapFile(). And I think the option parser will reject something like -map without an argument, so we don't need to warn (but I haven't verified this) |
maybe check and warn if the path is empty?