[PATCH] D44004: [ELF] - Show data commands in a map file.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 2 05:23:33 PST 2018


grimar created this revision.
grimar added reviewers: ruiu, rafael.
Herald added subscribers: arichardson, emaste.

With given below script:

  SECTIONS {
    . = 0x1000;
    .foo : {
      BYTE(0x11)
      SHORT(0x1122)
      LONG(0x11223344)
      QUAD(0x1122334455667788)
      *(.foo.1)
      . += 0x1000;
    }
  }

BFD shows data commands and location counter moving in the map file:

  .foo          0x0000000000001000      0x117
                  0x0000000000001000        0x1 BYTE 0x11
                  0x0000000000001001        0x2 SHORT 0x1122
                  0x0000000000001003        0x4 LONG 0x11223344
                  0x0000000000001007        0x8 QUAD 0x1122334455667788
   *(.foo.1)
   .foo.1         0x000000000000100f        0x8 map-file.test.tmp.o
                  0x0000000000001117                . = (. + 0x100)
   *fill*         0x0000000000001017      0x100 

Patch teaches LLD to print data commands to map file.


https://reviews.llvm.org/D44004

Files:
  ELF/MapFile.cpp
  test/ELF/linkerscript/map-file.test


Index: test/ELF/linkerscript/map-file.test
===================================================================
--- test/ELF/linkerscript/map-file.test
+++ test/ELF/linkerscript/map-file.test
@@ -0,0 +1,28 @@
+# REQUIRES: x86
+
+# RUN: echo ".section .foo.1,\"a\"" > %t.s
+# RUN: echo ".quad 1" >> %t.s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o
+
+# RUN: ld.lld -o %t %t.o -Map=%t.map --script %s
+
+SECTIONS {
+  . = 0x1000;
+  .foo : {
+    BYTE(0x11)
+    SHORT(0x1122)
+    LONG(0x11223344)
+    QUAD(0x1122334455667788)
+    *(.foo.1)
+  }
+}
+
+# CHECK:      Address          Size             Align Out     In      Symbol
+# CHECK-NEXT: 0000000000001000 0000000000000117     1 .foo
+# CHECK-NEXT: 0000000000001000 0000000000000001     1         BYTE 0x11
+# CHECK-NEXT: 0000000000001001 0000000000000002     2         SHORT 0x1122
+# CHECK-NEXT: 0000000000001003 0000000000000004     4         LONG 0x11223344
+# CHECK-NEXT: 0000000000001007 0000000000000008     8         QUAD 0x1122334455667788
+# CHECK-NEXT: 000000000000100f 0000000000000008     1         {{.*}}{{/|\\}}map-file.test.tmp.o:(.foo.1)
+# CHECK-NEXT: 0000000000001118 0000000000000000     4 .text
+# CHECK-NEXT: 0000000000001118 0000000000000000     4         {{.*}}{{/|\\}}map-file.test.tmp.o:(.text)
Index: ELF/MapFile.cpp
===================================================================
--- ELF/MapFile.cpp
+++ ELF/MapFile.cpp
@@ -137,11 +137,37 @@
     OS << OSec->Name << '\n';
 
     // Dump symbols for each input section.
-    for (InputSection *IS : getInputSections(OSec)) {
-      writeHeader(OS, OSec->Addr + IS->OutSecOff, IS->getSize(), IS->Alignment);
-      OS << indent(1) << toString(IS) << '\n';
-      for (Symbol *Sym : SectionSyms[IS])
-        OS << SymStr[Sym] << '\n';
+    for (BaseCommand *Base : OSec->SectionCommands) {
+      if (auto *ISD = dyn_cast<InputSectionDescription>(Base)) {
+        for (InputSection *IS : ISD->Sections) {
+          writeHeader(OS, OSec->Addr + IS->OutSecOff, IS->getSize(),
+                      IS->Alignment);
+          OS << indent(1) << toString(IS) << '\n';
+          for (Symbol *Sym : SectionSyms[IS])
+            OS << SymStr[Sym] << '\n';
+        }
+        continue;
+      }
+
+      if (auto *Cmd = dyn_cast<ByteCommand>(Base)) {
+        auto Print = [&](StringRef Name) {
+          writeHeader(OS, OSec->Addr + Cmd->Offset, Cmd->Size, Cmd->Size);
+          OS << indent(1) << Name << ' '
+             << format("0x%0*llx", Cmd->Size, Cmd->Expression().getValue())
+             << '\n';
+        };
+        if (Cmd->Size == 1)
+          Print("BYTE");
+        else if (Cmd->Size == 2)
+          Print("SHORT");
+        else if (Cmd->Size == 4)
+          Print("LONG");
+        else if (Cmd->Size == 8)
+          Print("QUAD");
+        else
+          llvm_unreachable("invalid data command size");
+        continue;
+      }
     }
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44004.136722.patch
Type: text/x-patch
Size: 2938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180302/8c0d8256/attachment.bin>


More information about the llvm-commits mailing list