This is an archive of the discontinued LLVM Phabricator instance.

[lld][ELF] Implement –print-memory-usage
ClosedPublic

Authored by phosek on May 16 2023, 12:25 AM.

Details

Summary

This option was introduced in GNU ld in
https://sourceware.org/legacy-ml/binutils/2015-06/msg00086.html and is
often used in embedded development. This change implements this option
in LLD matching the GNU ld output verbatim.

Diff Detail

Event Timeline

phosek created this revision.May 16 2023, 12:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2023, 12:25 AM
phosek requested review of this revision.May 16 2023, 12:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2023, 12:25 AM

Looks like a useful feature to add, and I agree that keeping the same syntax as GNU is worthwhile.

lld/ELF/LinkerScript.cpp
1450

Wondering whether it is worth making length() and usedLength() member functions of MemoryRegion. I think the (m->length)().getValue() is used at least once in LinkerScript.cpp.

Not got a strong opinion here, it would just hide a bit of the code needed to access the expression.

lld/test/ELF/linkerscript/print-memory-usage1.s
3 ↗(On Diff #522462)

More recent tests have used the split-file command to have the linker script and the assembler in the same file without needing a large echo command. This makes a bit easier to edit.

Will be worth checking with MaskRay to see his preference is though.

phosek updated this revision to Diff 524612.May 23 2023, 1:47 AM
phosek marked an inline comment as done.
phosek added inline comments.
lld/test/ELF/linkerscript/print-memory-usage1.s
3 ↗(On Diff #522462)

I was following the existing memory*.s test cases for consistency but I'm fine changing these to use split-file if that's @MaskRay's preference?

MaskRay added inline comments.May 23 2023, 12:47 PM
lld/test/ELF/linkerscript/print-memory-usage1.s
3 ↗(On Diff #522462)

The linker script seems too long. Using split-file should be clearer for this test.

And consider combining print-memory-usage1.s and print-memory-usage2.s and print-memory-usage3.s into one file.

phosek updated this revision to Diff 524979.May 23 2023, 7:44 PM
phosek marked 2 inline comments as done.
peter.smith accepted this revision.May 24 2023, 1:34 AM

Thanks very much for the updates. LGTM

This revision is now accepted and ready to land.May 24 2023, 1:34 AM

@MaskRay does this look good to you as well?

MaskRay accepted this revision.May 24 2023, 12:17 PM

Some nits.

lld/ELF/LinkerScript.h
340
lld/test/ELF/linkerscript/print-memory-usage.s
5
14

When testing whitespace formatting, we should use --match-full-lines --strict-whitespace. See why-extract.s

MaskRay added inline comments.May 24 2023, 12:18 PM
lld/ELF/LinkerScript.cpp
1456
lld/test/ELF/linkerscript/print-memory-usage.s
18

If you want to test that there is not output after the header, use CHECK2-NOT: {{.}}

phosek updated this revision to Diff 525460.May 25 2023, 12:14 AM
phosek marked 5 inline comments as done.
This revision was landed with ongoing or failed builds.May 25 2023, 12:14 AM
This revision was automatically updated to reflect the committed changes.