[llvm] 2667be0 - [JITLink][MachO] Error on N_EXT symbols with illegal string-table index 0.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 28 19:58:34 PST 2023


Author: Lang Hames
Date: 2023-01-28T19:58:27-08:00
New Revision: 2667be0eb85b65f95d5cf303162219d067de11ae

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

LOG: [JITLink][MachO] Error on N_EXT symbols with illegal string-table index 0.

Index 0 is reserved for anonymous symbols, which can't have the N_EXT bit
set (since N_EXT means non-local scope, and non-local scope requires a name).

Added: 
    llvm/test/ExecutionEngine/JITLink/X86/MachO_unnamed_external.yaml

Modified: 
    llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp
index 9876899933979..a520008aeb001 100644
--- a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp
@@ -267,7 +267,11 @@ Error MachOLinkGraphBuilder::createNormalizedSymbols() {
         Name = *NameOrErr;
       else
         return NameOrErr.takeError();
-    }
+    } else if (Type & MachO::N_EXT)
+      return make_error<JITLinkError>("Symbol at index " +
+                                      formatv("{0}", SymbolIndex) +
+                                      " has no name (string table index 0), "
+                                      "but N_EXT bit is set");
 
     LLVM_DEBUG({
       dbgs() << "  ";

diff  --git a/llvm/test/ExecutionEngine/JITLink/X86/MachO_unnamed_external.yaml b/llvm/test/ExecutionEngine/JITLink/X86/MachO_unnamed_external.yaml
new file mode 100644
index 0000000000000..771a22ba8f3f1
--- /dev/null
+++ b/llvm/test/ExecutionEngine/JITLink/X86/MachO_unnamed_external.yaml
@@ -0,0 +1,109 @@
+# RUN: yaml2obj %s -o %t
+# RUN: not llvm-jitlink -noexec -entry _anchor %t 2>&1 | FileCheck %s
+
+# Test that we generate an error (rather than crashing) if we encounter a
+# symbol with a string index of zero (no name) with the N_EXT bit set.
+
+# CHECK: Symbol at index 1 has no name (string table index 0), but N_EXT bit
+
+--- !mach-o
+FileHeader:
+  magic:           0xFEEDFACF
+  cputype:         0x1000007
+  cpusubtype:      0x3
+  filetype:        0x1
+  ncmds:           4
+  sizeofcmds:      360
+  flags:           0x2000
+  reserved:        0x0
+LoadCommands:
+  - cmd:             LC_SEGMENT_64
+    cmdsize:         232
+    segname:         ''
+    vmaddr:          0
+    vmsize:          8
+    fileoff:         392
+    filesize:        0
+    maxprot:         7
+    initprot:        7
+    nsects:          2
+    flags:           0
+    Sections:
+      - sectname:        __text
+        segname:         __TEXT
+        addr:            0x0
+        size:            0
+        offset:          0x188
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x80000000
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         ''
+      - sectname:        __common
+        segname:         __DATA
+        addr:            0x0
+        size:            8
+        offset:          0x0
+        align:           2
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x1
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+  - cmd:             LC_BUILD_VERSION
+    cmdsize:         24
+    platform:        1
+    minos:           851968
+    sdk:             0
+    ntools:          0
+  - cmd:             LC_SYMTAB
+    cmdsize:         24
+    symoff:          392
+    nsyms:           2
+    stroff:          424
+    strsize:         16
+  - cmd:             LC_DYSYMTAB
+    cmdsize:         80
+    ilocalsym:       0
+    nlocalsym:       0
+    iextdefsym:      0
+    nextdefsym:      2
+    iundefsym:       2
+    nundefsym:       0
+    tocoff:          0
+    ntoc:            0
+    modtaboff:       0
+    nmodtab:         0
+    extrefsymoff:    0
+    nextrefsyms:     0
+    indirectsymoff:  0
+    nindirectsyms:   0
+    extreloff:       0
+    nextrel:         0
+    locreloff:       0
+    nlocrel:         0
+LinkEditData:
+  NameList:
+    - n_strx:          1
+      n_type:          0xF
+      n_sect:          2
+      n_desc:          0
+      n_value:         0
+    - n_strx:          0
+      n_type:          0xF
+      n_sect:          2
+      n_desc:          0
+      n_value:         4
+  StringTable:
+    - ''
+    - _anchor
+    - _b
+    - ''
+    - ''
+    - ''
+    - ''
+...


        


More information about the llvm-commits mailing list