[llvm] 517a484 - [llvm-jitlink] Add -alias option, shorten "-define-abs" option to "-abs".

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 3 00:00:05 PST 2022


Author: Lang Hames
Date: 2022-02-03T18:47:59+11:00
New Revision: 517a4844bf26da21b0c7454a9388500b62cd6106

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

LOG: [llvm-jitlink] Add -alias option, shorten "-define-abs" option to "-abs".

The -alias option can be used to define aliases within a JITDylib. The
immediate motivation is to simplify testing of ORC runtime functions using
existing testcases (e.g. by aliasing dlfcn functions to their ORC-runtime
counterparts, like -alias dlopen=__orc_rt_macho_dlopen). The option is likely
to be useful for testing in general.

The -define-abs option is shortened to -abs for consistency with -alias.

Added: 
    llvm/test/ExecutionEngine/JITLink/X86/MachO_llvm_jitlink_alias_option.s

Modified: 
    llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_relocations.s
    llvm/test/ExecutionEngine/JITLink/RISCV/ELF_abs_reloc.s
    llvm/test/ExecutionEngine/JITLink/RISCV/ELF_branch.s
    llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
    llvm/test/ExecutionEngine/JITLink/RISCV/ELF_riscv32_got_plt_reloc.s
    llvm/test/ExecutionEngine/JITLink/RISCV/ELF_riscv64_got_plt_reloc.s
    llvm/test/ExecutionEngine/JITLink/X86/ELF_ehframe_basic.s
    llvm/test/ExecutionEngine/JITLink/X86/ELF_x86-64_got_plt_optimizations.s
    llvm/test/ExecutionEngine/JITLink/X86/ELF_x86-64_small_pic_relocations.s
    llvm/test/ExecutionEngine/JITLink/X86/ELF_x86_64_absolute_relocations.s
    llvm/test/ExecutionEngine/JITLink/X86/LocalDependencyPropagation.s
    llvm/test/ExecutionEngine/JITLink/X86/MachO_weak_references.s
    llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_ehframe.test
    llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_relocations.s
    llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_relocations.s b/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_relocations.s
index 5d4539df6a71f..10158645c760a 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 d4d9ff37bf23e..b70f8f816b3b3 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 5bafcc4d477cd..0e7a83eff1c80 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 32897e32bc9f1..a5381b3f9cee1 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 c8df4856ca698..0990df348292e 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 e5b789d03160a..8e01b08b5e1ca 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 170843b88299e..1b3ff16ea1495 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 6090cc960eb04..7ec72cc1fb90a 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 59981f1e9314e..83e7f7c53e797 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 caaaeee87ed40..f7ce00acb32a8 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 68b1aa9b465da..d70cdfa077517 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 0000000000000..fc35294988d65
--- /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 at 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 20fa5536302d7..1395bb500d90a 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 08c616f8f0f01..b6ebddbacf4c9 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 7efef9c52f6b1..fc59f6647eefe 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 aacac7279b599..3dc17677c0a8a 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -136,10 +136,14 @@ static cl::opt<bool>
                      cl::init(false), cl::cat(JITLinkCategory));
 
 static cl::list<std::string> AbsoluteDefs(
-    "define-abs",
+    "abs",
     cl::desc("Inject absolute symbol definitions (syntax: <name>=<addr>)"),
     cl::ZeroOrMore, cl::cat(JITLinkCategory));
 
+static cl::list<std::string>
+    Aliases("alias", cl::desc("Inject symbol aliases (syntax: <name>=<addr>)"),
+            cl::ZeroOrMore, cl::cat(JITLinkCategory));
+
 static cl::list<std::string> 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<StringError>("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<unsigned, JITDylib *> &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<StringError>("Invalid alias definition \"" + AliasStmt +
+                                         "\". Syntax: <name>=<addr>",
+                                     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;


        


More information about the llvm-commits mailing list