[lld] c00fc18 - [llvm-readobj] Recognize N_THUMB_DEF as a symbol flag

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 30 14:40:55 PDT 2021


Author: Jez Ng
Date: 2021-04-30T17:39:56-04:00
New Revision: c00fc180ecdac4b13caddd1ba506ffa3f6e7e206

URL: https://github.com/llvm/llvm-project/commit/c00fc180ecdac4b13caddd1ba506ffa3f6e7e206
DIFF: https://github.com/llvm/llvm-project/commit/c00fc180ecdac4b13caddd1ba506ffa3f6e7e206.diff

LOG: [llvm-readobj] Recognize N_THUMB_DEF as a symbol flag

The right symbol flag mask is ~0x7, not ~0xf.

Also emit string names for the other flags (we were missing some).

Reviewed By: #lld-macho, gkm

Differential Revision: https://reviews.llvm.org/D101548

Added: 
    llvm/test/tools/llvm-readobj/MachO/flags.yaml

Modified: 
    lld/test/MachO/symtab.s
    llvm/test/MC/MachO/ARM/darwin-Thumb-reloc.s
    llvm/test/tools/llvm-objcopy/MachO/symbol-table.test
    llvm/tools/llvm-readobj/MachODumper.cpp

Removed: 
    


################################################################################
diff  --git a/lld/test/MachO/symtab.s b/lld/test/MachO/symtab.s
index 7dff1b029ffe..5a26bfd55059 100644
--- a/lld/test/MachO/symtab.s
+++ b/lld/test/MachO/symtab.s
@@ -73,6 +73,7 @@
 # CHECK-NEXT:     Section:  (0x0)
 # CHECK-NEXT:     RefType: UndefinedNonLazy (0x0)
 # CHECK-NEXT:     Flags [ (0x100)
+# CHECK-NEXT:       SymbolResolver (0x100)
 # CHECK-NEXT:     ]
 # CHECK-NEXT:     Value: 0x0
 # CHECK-NEXT:   }

diff  --git a/llvm/test/MC/MachO/ARM/darwin-Thumb-reloc.s b/llvm/test/MC/MachO/ARM/darwin-Thumb-reloc.s
index c387a292ba2f..2e69aceedbc0 100644
--- a/llvm/test/MC/MachO/ARM/darwin-Thumb-reloc.s
+++ b/llvm/test/MC/MachO/ARM/darwin-Thumb-reloc.s
@@ -92,8 +92,9 @@ L_.str:
 @ CHECK:     Extern
 @ CHECK:     Type: Section (0xE)
 @ CHECK:     Section: __text (0x1)
-@ CHECK:     RefType: 0x8
-@ CHECK:     Flags [ (0x0)
+@ CHECK:     RefType: UndefinedNonLazy (0x0)
+@ CHECK:     Flags [ (0x8)
+@ CHECK:       ThumbDef (0x8)
 @ CHECK:     ]
 @ CHECK:     Value: 0x0
 @ CHECK:   }

diff  --git a/llvm/test/tools/llvm-objcopy/MachO/symbol-table.test b/llvm/test/tools/llvm-objcopy/MachO/symbol-table.test
index 355ccd48c4d1..7e0e1421c064 100644
--- a/llvm/test/tools/llvm-objcopy/MachO/symbol-table.test
+++ b/llvm/test/tools/llvm-objcopy/MachO/symbol-table.test
@@ -180,6 +180,7 @@
 # CHECK-NEXT:     RefType: UndefinedNonLazy (0x0)
 # CHECK-NEXT:     Flags [ (0xFE00)
 # CHECK-NEXT:       AltEntry (0x200)
+# CHECK-NEXT:       ColdFunc (0x400)
 # CHECK-NEXT:     ]
 # CHECK-NEXT:     Value: 0x0
 # CHECK-NEXT:   }
@@ -190,6 +191,7 @@
 # CHECK-NEXT:     Section:  (0x0)
 # CHECK-NEXT:     RefType: UndefinedNonLazy (0x0)
 # CHECK-NEXT:     Flags [ (0x100)
+# CHECK-NEXT:       SymbolResolver (0x100)
 # CHECK-NEXT:     ]
 # CHECK-NEXT:     Value: 0x0
 # CHECK-NEXT:   }

diff  --git a/llvm/test/tools/llvm-readobj/MachO/flags.yaml b/llvm/test/tools/llvm-readobj/MachO/flags.yaml
new file mode 100644
index 000000000000..fc80b3bf6513
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/MachO/flags.yaml
@@ -0,0 +1,74 @@
+## Verify that llvm-readobj can dump the various symbol flags correctly.
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-readobj --syms %t | FileCheck %s
+
+# CHECK:      Symbols [
+# CHECK-NEXT:   Symbol {
+# CHECK-NEXT:     Name: _foo (1)
+# CHECK-NEXT:     Extern
+# CHECK-NEXT:     Type: Section (0xE)
+# CHECK-NEXT:     Section: __text (0x1)
+# CHECK-NEXT:     RefType: UndefinedNonLazy (0x0)
+# CHECK-NEXT:     Flags [ (0x128)
+# CHECK-NEXT:       NoDeadStrip (0x20)
+# CHECK-NEXT:       SymbolResolver (0x100)
+# CHECK-NEXT:       ThumbDef (0x8)
+# CHECK-NEXT:     ]
+# CHECK-NEXT:     Value: 0x0
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
+
+--- !mach-o
+FileHeader:
+  magic:           0xFEEDFACE
+  cputype:         0xC
+  cpusubtype:      0x9
+  filetype:        0x1
+  ncmds:           2
+  sizeofcmds:      228
+  flags:           0x0
+LoadCommands:
+  - cmd:             LC_SEGMENT
+    cmdsize:         124
+    segname:         ''
+    vmaddr:          0
+    vmsize:          0
+    fileoff:         256
+    filesize:        0
+    maxprot:         7
+    initprot:        7
+    nsects:          1
+    flags:           0
+    Sections:
+      - sectname:        __text
+        segname:         __TEXT
+        addr:            0x0
+        size:            0
+        offset:          0x100
+        align:           2
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x80000000
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         ''
+  - cmd:             LC_SYMTAB
+    cmdsize:         24
+    symoff:          256
+    nsyms:           1
+    stroff:          268
+    strsize:         8
+LinkEditData:
+  NameList:
+    - n_strx:          1
+      n_type:          0xF
+      n_sect:          1
+      n_desc:          296
+      n_value:         0
+  StringTable:
+    - ''
+    - _foo
+    - ''
+    - ''
+...

diff  --git a/llvm/tools/llvm-readobj/MachODumper.cpp b/llvm/tools/llvm-readobj/MachODumper.cpp
index c13b1f3bf2a0..433ca9335324 100644
--- a/llvm/tools/llvm-readobj/MachODumper.cpp
+++ b/llvm/tools/llvm-readobj/MachODumper.cpp
@@ -256,11 +256,14 @@ static const EnumEntry<unsigned> MachOSymbolRefTypes[] = {
 };
 
 static const EnumEntry<unsigned> MachOSymbolFlags[] = {
+  { "ThumbDef",               0x8 },
   { "ReferencedDynamically", 0x10 },
   { "NoDeadStrip",           0x20 },
   { "WeakRef",               0x40 },
   { "WeakDef",               0x80 },
+  { "SymbolResolver",       0x100 },
   { "AltEntry",             0x200 },
+  { "ColdFunc",             0x400 },
 };
 
 static const EnumEntry<unsigned> MachOSymbolTypes[] = {
@@ -651,9 +654,9 @@ void MachODumper::printSymbol(const SymbolRef &Symbol) {
                 makeArrayRef(MachOSymbolTypes));
   }
   W.printHex("Section", SectionName, MOSymbol.SectionIndex);
-  W.printEnum("RefType", static_cast<uint16_t>(MOSymbol.Flags & 0xF),
+  W.printEnum("RefType", static_cast<uint16_t>(MOSymbol.Flags & 0x7),
               makeArrayRef(MachOSymbolRefTypes));
-  W.printFlags("Flags", static_cast<uint16_t>(MOSymbol.Flags & ~0xF),
+  W.printFlags("Flags", static_cast<uint16_t>(MOSymbol.Flags & ~0x7),
                makeArrayRef(MachOSymbolFlags));
   W.printHex("Value", MOSymbol.Value);
 }


        


More information about the llvm-commits mailing list