[llvm] 5273773 - [JITLink] Allow duplicate symbol names for locals
Ben Langmuir via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 17 09:32:20 PST 2021
Author: Ben Langmuir
Date: 2021-11-17T09:31:51-08:00
New Revision: 5273773580f631f853ca43586d9912c000b473d4
URL: https://github.com/llvm/llvm-project/commit/5273773580f631f853ca43586d9912c000b473d4
DIFF: https://github.com/llvm/llvm-project/commit/5273773580f631f853ca43586d9912c000b473d4.diff
LOG: [JITLink] Allow duplicate symbol names for locals
Local symbols can have the same name. I ran into this with JITLink
while working with an object file that had been run through `strip -S`
that had many "func.eh" symbols, but it can also happen using `ld -r`.
rdar://85352156
Differential Revision: https://reviews.llvm.org/D114042
Added:
llvm/test/ExecutionEngine/JITLink/X86/MachO-duplicate-local.test
Modified:
llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
index a9a54e59ef51d..6087861ff7362 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
@@ -1120,11 +1120,11 @@ class LinkGraph {
Symbol &addDefinedSymbol(Block &Content, JITTargetAddress Offset,
StringRef Name, JITTargetAddress Size, Linkage L,
Scope S, bool IsCallable, bool IsLive) {
- assert(llvm::count_if(defined_symbols(),
- [&](const Symbol *Sym) {
- return Sym->getName() == Name;
- }) == 0 &&
- "Duplicate defined symbol");
+ assert(S == Scope::Local || llvm::count_if(defined_symbols(),
+ [&](const Symbol *Sym) {
+ return Sym->getName() == Name;
+ }) == 0 &&
+ "Duplicate defined symbol");
auto &Sym =
Symbol::constructNamedDef(Allocator.Allocate<Symbol>(), Content, Offset,
Name, Size, L, S, IsLive, IsCallable);
diff --git a/llvm/test/ExecutionEngine/JITLink/X86/MachO-duplicate-local.test b/llvm/test/ExecutionEngine/JITLink/X86/MachO-duplicate-local.test
new file mode 100644
index 0000000000000..25def26e3b7ca
--- /dev/null
+++ b/llvm/test/ExecutionEngine/JITLink/X86/MachO-duplicate-local.test
@@ -0,0 +1,123 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-jitlink -noexec -show-graph %t | FileCheck %s
+
+# The below describes an object with two local symbols named _foo, each
+# referenced by _main to keep it live. Ensure we can link it.
+
+# CHECK: scope: local, live - _foo
+# CHECK: scope: local, live - _foo
+# CHECK: scope: default, live - _main
+# CHECK-NEXT: edges:
+# CHECK-NEXT: target = _foo
+# CHECK-NEXT: target = _foo
+
+--- !mach-o
+FileHeader:
+ magic: 0xFEEDFACF
+ cputype: 0x1000007
+ cpusubtype: 0x3
+ filetype: 0x1
+ ncmds: 4
+ sizeofcmds: 280
+ flags: 0x0
+ reserved: 0x0
+LoadCommands:
+ - cmd: LC_SEGMENT_64
+ cmdsize: 152
+ segname: ''
+ vmaddr: 0
+ vmsize: 13
+ fileoff: 312
+ filesize: 13
+ maxprot: 7
+ initprot: 7
+ nsects: 1
+ flags: 0
+ Sections:
+ - sectname: __text
+ segname: __TEXT
+ addr: 0x0
+ size: 13
+ offset: 0x138
+ align: 0
+ reloff: 0x145
+ nreloc: 2
+ flags: 0x80000400
+ reserved1: 0x0
+ reserved2: 0x0
+ reserved3: 0x0
+ content: 9090E800000000E80000000090
+ relocations:
+ - address: 0x8
+ symbolnum: 1
+ pcrel: true
+ length: 2
+ extern: true
+ type: 2
+ scattered: false
+ value: 0
+ - address: 0x3
+ symbolnum: 0
+ pcrel: true
+ length: 2
+ extern: true
+ type: 2
+ scattered: false
+ value: 0
+ - cmd: LC_BUILD_VERSION
+ cmdsize: 24
+ platform: 1
+ minos: 786432
+ sdk: 0
+ ntools: 0
+ - cmd: LC_SYMTAB
+ cmdsize: 24
+ symoff: 341
+ nsyms: 3
+ stroff: 389
+ strsize: 16
+ - cmd: LC_DYSYMTAB
+ cmdsize: 80
+ ilocalsym: 0
+ nlocalsym: 2
+ iextdefsym: 2
+ nextdefsym: 1
+ iundefsym: 3
+ 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: 0xE
+ n_sect: 1
+ n_desc: 0
+ n_value: 0
+ - n_strx: 1
+ n_type: 0xE
+ n_sect: 1
+ n_desc: 0
+ n_value: 1
+ - n_strx: 6
+ n_type: 0xF
+ n_sect: 1
+ n_desc: 0
+ n_value: 2
+ StringTable:
+ - ''
+ - _foo
+ - _main
+ - ''
+ - ''
+ - ''
+ - ''
\ No newline at end of file
More information about the llvm-commits
mailing list