diff --git a/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_relocations.s b/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_relocations.s index 5d4539df6a71..10158645c760 100644 --- a/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_relocations.s +++ b/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_relocations.s @@ -1,6 +1,6 @@ # RUN: rm -rf %t && mkdir -p %t # RUN: llvm-mc -triple=arm64-apple-darwin19 -filetype=obj -o %t/macho_reloc.o %s -# RUN: llvm-jitlink -noexec -define-abs external_data=0xdeadbeef -define-abs external_func=0xcafef00d -check=%s %t/macho_reloc.o +# RUN: llvm-jitlink -noexec -abs external_data=0xdeadbeef -abs external_func=0xcafef00d -check=%s %t/macho_reloc.o .section __TEXT,__text,regular,pure_instructions diff --git a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_abs_reloc.s b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_abs_reloc.s index d4d9ff37bf23..b70f8f816b3b 100644 --- a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_abs_reloc.s +++ b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_abs_reloc.s @@ -5,11 +5,11 @@ # RUN: -o %t/elf_riscv32_non_pc_indirect_reloc.o %s # RUN: llvm-jitlink -noexec \ # RUN: -slab-allocate 100Kb -slab-address 0x1ff00000 -slab-page-size 4096 \ -# RUN: -define-abs external_data=0x1ff10000 \ +# RUN: -abs external_data=0x1ff10000 \ # RUN: -check %s %t/elf_riscv64_non_pc_indirect_reloc.o # RUN: llvm-jitlink -noexec \ # RUN: -slab-allocate 100Kb -slab-address 0x1ff00000 -slab-page-size 4096 \ -# RUN: -define-abs external_data=0x1ff10000 \ +# RUN: -abs external_data=0x1ff10000 \ # RUN: -check %s %t/elf_riscv32_non_pc_indirect_reloc.o # diff --git a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_branch.s b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_branch.s index 5bafcc4d477c..0e7a83eff1c8 100644 --- a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_branch.s +++ b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_branch.s @@ -5,11 +5,11 @@ # RUN: -o %t/elf_riscv32_branch.o %s # RUN: llvm-jitlink -noexec \ # RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \ -# RUN: -define-abs external_func=0xfe \ +# RUN: -abs external_func=0xfe \ # RUN: -check %s %t/elf_riscv64_branch.o # RUN: llvm-jitlink -noexec \ # RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \ -# RUN: -define-abs external_func=0xfe \ +# RUN: -abs external_func=0xfe \ # RUN: -check %s %t/elf_riscv32_branch.o # diff --git a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s index 32897e32bc9f..a5381b3f9cee 100644 --- a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s +++ b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s @@ -5,11 +5,11 @@ # RUN: -o %t/elf_riscv32_sm_pic_reloc.o %s # RUN: llvm-jitlink -noexec \ # RUN: -slab-allocate 100Kb -slab-address 0x1ff00000 -slab-page-size 4096 \ -# RUN: -define-abs external_func=0x1 -define-abs external_data=0x2 \ +# RUN: -abs external_func=0x1 -abs external_data=0x2 \ # RUN: -check %s %t/elf_riscv64_sm_pic_reloc.o # RUN: llvm-jitlink -noexec \ # RUN: -slab-allocate 100Kb -slab-address 0x1ff00000 -slab-page-size 4096 \ -# RUN: -define-abs external_func=0x1 -define-abs external_data=0x2 \ +# RUN: -abs external_func=0x1 -abs external_data=0x2 \ # RUN: -check %s %t/elf_riscv32_sm_pic_reloc.o # # Test ELF small/PIC relocations diff --git a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_riscv32_got_plt_reloc.s b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_riscv32_got_plt_reloc.s index c8df4856ca69..0990df348292 100644 --- a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_riscv32_got_plt_reloc.s +++ b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_riscv32_got_plt_reloc.s @@ -3,7 +3,7 @@ # RUN: -o %t/elf_riscv32_got_plt_reloc.o %s # RUN: llvm-jitlink -noexec \ # RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \ -# RUN: -define-abs external_func=0x1 -define-abs external_data=0x2 \ +# RUN: -abs external_func=0x1 -abs external_data=0x2 \ # RUN: -check %s %t/elf_riscv32_got_plt_reloc.o .text diff --git a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_riscv64_got_plt_reloc.s b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_riscv64_got_plt_reloc.s index e5b789d03160..8e01b08b5e1c 100644 --- a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_riscv64_got_plt_reloc.s +++ b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_riscv64_got_plt_reloc.s @@ -3,7 +3,7 @@ # RUN: -o %t/elf_riscv64_got_plt_reloc.o %s # RUN: llvm-jitlink -noexec \ # RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \ -# RUN: -define-abs external_func=0x1 -define-abs external_data=0x2 \ +# RUN: -abs external_func=0x1 -abs external_data=0x2 \ # RUN: -check %s %t/elf_riscv64_got_plt_reloc.o diff --git a/llvm/test/ExecutionEngine/JITLink/X86/ELF_ehframe_basic.s b/llvm/test/ExecutionEngine/JITLink/X86/ELF_ehframe_basic.s index 170843b88299..1b3ff16ea149 100644 --- a/llvm/test/ExecutionEngine/JITLink/X86/ELF_ehframe_basic.s +++ b/llvm/test/ExecutionEngine/JITLink/X86/ELF_ehframe_basic.s @@ -2,8 +2,8 @@ # UNSUPPORTED: system-windows # RUN: llvm-mc -triple=x86_64-unknown-linux -position-independent \ # RUN: -filetype=obj -o %t %s -# RUN: llvm-jitlink -debug-only=jitlink -define-abs bar=0x01 \ -# RUN: -define-abs _ZTIi=0x02 -noexec %t 2>&1 | FileCheck %s +# RUN: llvm-jitlink -debug-only=jitlink -abs bar=0x01 \ +# RUN: -abs _ZTIi=0x02 -noexec %t 2>&1 | FileCheck %s # # FIXME: This test should run on windows. Investigate spurious # 'note: command had no output on stdout or stderr' errors, then re-enable. diff --git a/llvm/test/ExecutionEngine/JITLink/X86/ELF_x86-64_got_plt_optimizations.s b/llvm/test/ExecutionEngine/JITLink/X86/ELF_x86-64_got_plt_optimizations.s index 6090cc960eb0..7ec72cc1fb90 100644 --- a/llvm/test/ExecutionEngine/JITLink/X86/ELF_x86-64_got_plt_optimizations.s +++ b/llvm/test/ExecutionEngine/JITLink/X86/ELF_x86-64_got_plt_optimizations.s @@ -3,7 +3,7 @@ # RUN: -filetype=obj -o %t/elf_sm_pic_reloc.o %s # RUN: llvm-jitlink -noexec \ # RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \ -# RUN: -define-abs extern_in_range32=0xffe00000 \ +# RUN: -abs extern_in_range32=0xffe00000 \ # RUN: -check %s %t/elf_sm_pic_reloc.o # diff --git a/llvm/test/ExecutionEngine/JITLink/X86/ELF_x86-64_small_pic_relocations.s b/llvm/test/ExecutionEngine/JITLink/X86/ELF_x86-64_small_pic_relocations.s index 59981f1e9314..83e7f7c53e79 100644 --- a/llvm/test/ExecutionEngine/JITLink/X86/ELF_x86-64_small_pic_relocations.s +++ b/llvm/test/ExecutionEngine/JITLink/X86/ELF_x86-64_small_pic_relocations.s @@ -3,8 +3,8 @@ # RUN: -filetype=obj -o %t/elf_sm_pic_reloc.o %s # RUN: llvm-jitlink -noexec \ # RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \ -# RUN: -define-abs external_data=0x1 \ -# RUN: -define-abs extern_out_of_range32=0x7fff00000000 \ +# RUN: -abs external_data=0x1 \ +# RUN: -abs extern_out_of_range32=0x7fff00000000 \ # RUN: -check %s %t/elf_sm_pic_reloc.o # # Test ELF small/PIC relocations. diff --git a/llvm/test/ExecutionEngine/JITLink/X86/ELF_x86_64_absolute_relocations.s b/llvm/test/ExecutionEngine/JITLink/X86/ELF_x86_64_absolute_relocations.s index caaaeee87ed4..f7ce00acb32a 100644 --- a/llvm/test/ExecutionEngine/JITLink/X86/ELF_x86_64_absolute_relocations.s +++ b/llvm/test/ExecutionEngine/JITLink/X86/ELF_x86_64_absolute_relocations.s @@ -3,8 +3,8 @@ # RUN: -filetype=obj -o %t/elf_abs_reloc.o %s # RUN: llvm-jitlink -noexec \ # RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \ -# RUN: -define-abs external_data_low=0x1 \ -# RUN: -define-abs external_data_high=0xffffffff80000000 \ +# RUN: -abs external_data_low=0x1 \ +# RUN: -abs external_data_high=0xffffffff80000000 \ # RUN: -check %s %t/elf_abs_reloc.o # # Test ELF absolute relocations. diff --git a/llvm/test/ExecutionEngine/JITLink/X86/LocalDependencyPropagation.s b/llvm/test/ExecutionEngine/JITLink/X86/LocalDependencyPropagation.s index 68b1aa9b465d..d70cdfa07751 100644 --- a/llvm/test/ExecutionEngine/JITLink/X86/LocalDependencyPropagation.s +++ b/llvm/test/ExecutionEngine/JITLink/X86/LocalDependencyPropagation.s @@ -1,6 +1,6 @@ # REQUIRES: asserts # RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t %s -# RUN: llvm-jitlink -debug-only=orc -noexec -define-abs _external_func=0x1 \ +# RUN: llvm-jitlink -debug-only=orc -noexec -abs _external_func=0x1 \ # RUN: -entry=_foo %t 2>&1 | FileCheck %s # # Verify that symbol dependencies are correctly propagated through local diff --git a/llvm/test/ExecutionEngine/JITLink/X86/MachO_llvm_jitlink_alias_option.s b/llvm/test/ExecutionEngine/JITLink/X86/MachO_llvm_jitlink_alias_option.s new file mode 100644 index 000000000000..fc35294988d6 --- /dev/null +++ b/llvm/test/ExecutionEngine/JITLink/X86/MachO_llvm_jitlink_alias_option.s @@ -0,0 +1,20 @@ +# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t.o %s +# RUN: llvm-jitlink -noexec -alias x=y %t.o +# +# Check that the -alias option works. + + .section __TEXT,__text,regular,pure_instructions + .globl _main + .p2align 4, 0x90 +_main: + movq x@GOTPCREL(%rip), %rax + movl (%rax), %eax + retq + + .section __DATA,__data + .globl y + .p2align 2 +y: + .long 42 + +.subsections_via_symbols diff --git a/llvm/test/ExecutionEngine/JITLink/X86/MachO_weak_references.s b/llvm/test/ExecutionEngine/JITLink/X86/MachO_weak_references.s index 20fa5536302d..1395bb500d90 100644 --- a/llvm/test/ExecutionEngine/JITLink/X86/MachO_weak_references.s +++ b/llvm/test/ExecutionEngine/JITLink/X86/MachO_weak_references.s @@ -1,6 +1,6 @@ # RUN: rm -rf %t && mkdir -p %t # RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t/macho_weak_refs.o %s -# RUN: llvm-jitlink -noexec -check-name=jitlink-check-bar-present -define-abs bar=0x1 -check=%s %t/macho_weak_refs.o +# RUN: llvm-jitlink -noexec -check-name=jitlink-check-bar-present -abs bar=0x1 -check=%s %t/macho_weak_refs.o # RUN: llvm-jitlink -noexec -check-name=jitlink-check-bar-absent -check=%s %t/macho_weak_refs.o # Test weak reference handling by linking with and without a definition of 'bar' available. diff --git a/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_ehframe.test b/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_ehframe.test index 08c616f8f0f0..b6ebddbacf4c 100644 --- a/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_ehframe.test +++ b/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_ehframe.test @@ -1,4 +1,4 @@ -# RUN: llvm-jitlink -noexec -define-abs __ZTIi=0x1 -define-abs ___gxx_personality_v0=0x2 %S/Inputs/MachO_x86-64_ehframe.o +# RUN: llvm-jitlink -noexec -abs __ZTIi=0x1 -abs ___gxx_personality_v0=0x2 %S/Inputs/MachO_x86-64_ehframe.o # # Perform a no-exec link of MachO_x86-64_ehframe and verify that it does not # generate any errors despite the last FDE referring to the first CIE (rather diff --git a/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_relocations.s b/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_relocations.s index 7efef9c52f6b..fc59f6647eef 100644 --- a/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_relocations.s +++ b/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_relocations.s @@ -2,7 +2,7 @@ # RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t/macho_reloc.o %s # RUN: llvm-jitlink -noexec \ # RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \ -# RUN: -define-abs external_data=0x1 -define-abs external_func=0x2 \ +# RUN: -abs external_data=0x1 -abs external_func=0x2 \ # RUN: -check=%s %t/macho_reloc.o # # Test standard MachO relocations. Simulates slab allocation in the top 1Mb of diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp index aacac7279b59..3dc17677c0a8 100644 --- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp @@ -136,10 +136,14 @@ static cl::opt cl::init(false), cl::cat(JITLinkCategory)); static cl::list AbsoluteDefs( - "define-abs", + "abs", cl::desc("Inject absolute symbol definitions (syntax: =)"), cl::ZeroOrMore, cl::cat(JITLinkCategory)); +static cl::list + Aliases("alias", cl::desc("Inject symbol aliases (syntax: =)"), + cl::ZeroOrMore, cl::cat(JITLinkCategory)); + static cl::list TestHarnesses("harness", cl::Positional, cl::desc("Test harness files"), cl::ZeroOrMore, @@ -1374,8 +1378,8 @@ static Error addAbsoluteSymbols(Session &S, uint64_t Addr; if (AddrStr.getAsInteger(0, Addr)) return make_error("Invalid address expression \"" + AddrStr + - "\" in absolute define \"" + AbsDefStmt + - "\"", + "\" in absolute symbol definition \"" + + AbsDefStmt + "\"", inconvertibleErrorCode()); JITEvaluatedSymbol AbsDef(Addr, JITSymbolFlags::Exported); if (auto Err = JD.define(absoluteSymbols({{S.ES.intern(Name), AbsDef}}))) @@ -1388,6 +1392,33 @@ static Error addAbsoluteSymbols(Session &S, return Error::success(); } +static Error addAliases(Session &S, + const std::map &IdxToJD) { + // Define absolute symbols. + LLVM_DEBUG(dbgs() << "Defining aliases...\n"); + for (auto AliasItr = Aliases.begin(), AliasEnd = Aliases.end(); + AliasItr != AliasEnd; ++AliasItr) { + unsigned AliasArgIdx = Aliases.getPosition(AliasItr - Aliases.begin()); + auto &JD = *std::prev(IdxToJD.lower_bound(AliasArgIdx))->second; + + StringRef AliasStmt = *AliasItr; + size_t EqIdx = AliasStmt.find_first_of('='); + if (EqIdx == StringRef::npos) + return make_error("Invalid alias definition \"" + AliasStmt + + "\". Syntax: =", + inconvertibleErrorCode()); + StringRef Alias = AliasStmt.substr(0, EqIdx).trim(); + StringRef Aliasee = AliasStmt.substr(EqIdx + 1).trim(); + + SymbolAliasMap SAM; + SAM[S.ES.intern(Alias)] = {S.ES.intern(Aliasee), JITSymbolFlags::Exported}; + if (auto Err = JD.define(symbolAliases(std::move(SAM)))) + return Err; + } + + return Error::success(); +} + static Error addTestHarnesses(Session &S) { LLVM_DEBUG(dbgs() << "Adding test harness objects...\n"); for (auto HarnessFile : TestHarnesses) { @@ -1711,6 +1742,9 @@ static Error addSessionInputs(Session &S) { if (auto Err = addAbsoluteSymbols(S, IdxToJD)) return Err; + if (auto Err = addAliases(S, IdxToJD)) + return Err; + if (!TestHarnesses.empty()) if (auto Err = addTestHarnesses(S)) return Err;