[PATCH] D118077: Print C-string literals in mapfile

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 7 08:56:00 PST 2022


int3 added inline comments.


================
Comment at: lld/MachO/MapFile.cpp:82-97
+    switch (sym->isec->kind()) {
+    case InputSection::CStringLiteralKind: {
+      // Output "literal string: <string literal>"
+      auto *isec = static_cast<CStringInputSection *>(sym->isec);
+      assert(isec != nullptr);
+      auto &piece = isec->getStringPiece(sym->value);
+      auto offset = sym->value - piece.outSecOff;
----------------
we don't need to match cstrings with symbols -- in fact, to follow ld64's behavior, we shouldn't. Given an input like
```
.cstring
_y:
.asciz "hi"
.asciz "unnamed"
```

The mapfile contains separate entries for "hi" and "unnamed", even though "unnamed" doesn't have a symbol associated with it.

So basically we can iterate from `i=0...isec->pieces.size()-1` and call `isec->getStringRef(i)` on each one. No need to work directly with the string pieces either :)


================
Comment at: lld/test/MachO/map-file.s:74-82
+# RUN: %lld -map %t/c-string-literal-map %t/c-string-literal.o -o %t/c-string-literal-out
+# RUN: cat %t/c-string-literal-map
+# RUN: FileCheck --check-prefix=CSTRING %s < %t/c-string-literal-map
+
+## C-string literals should be printed as "literal string: <C string literal>"
+# CSTRING-LABEL: Symbols:
+# CSTRING-DAG: _main
----------------
so most of the other tests have all the `RUN` and `CHECK` lines at the top, above the input files. I see that the other tests in this file have already interleaved them... could we fix that please? Thanks :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118077/new/

https://reviews.llvm.org/D118077



More information about the llvm-commits mailing list