[llvm] 151f809 - [JITLink] Demote symbol scope to local during external-to-absolute conversion.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 8 10:41:44 PST 2022


Author: Lang Hames
Date: 2022-03-08T10:31:20-08:00
New Revision: 151f809c558d3d7e67e4d4b7efe84218c3b8cfa7

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

LOG: [JITLink] Demote symbol scope to local during external-to-absolute conversion.

When an external symbol is converted to an absolute it should be demoted to
local scope so that the symbol does not become a new definition within this
LinkGraph.

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

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 25f1349f15f28..75d0ddfab556d 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
@@ -1215,8 +1215,11 @@ class LinkGraph {
   /// Make the given symbol an absolute with the given address (must not already
   /// be absolute).
   ///
-  /// Symbol size, linkage, scope, and callability, and liveness will be left
-  /// unchanged. Symbol offset will be reset to 0.
+  /// The symbol's size, linkage, and callability, and liveness will be left
+  /// unchanged, and its offset will be reset to 0.
+  ///
+  /// If the symbol was external then its scope will be set to local, otherwise
+  /// it will be left unchanged.
   void makeAbsolute(Symbol &Sym, orc::ExecutorAddr Address) {
     assert(!Sym.isAbsolute() && "Symbol is already absolute");
     if (Sym.isExternal()) {
@@ -1225,6 +1228,7 @@ class LinkGraph {
       assert(Sym.getOffset() == 0 && "External is not at offset 0");
       ExternalSymbols.erase(&Sym);
       Sym.getAddressable().setAbsolute(true);
+      Sym.setScope(Scope::Local);
     } else {
       assert(Sym.isDefined() && "Sym is not a defined symbol");
       Section &Sec = Sym.getBlock().getSection();

diff  --git a/llvm/test/ExecutionEngine/JITLink/X86/ELF_external_to_absolute_conversion.s b/llvm/test/ExecutionEngine/JITLink/X86/ELF_external_to_absolute_conversion.s
new file mode 100644
index 0000000000000..3cff5e0d1e750
--- /dev/null
+++ b/llvm/test/ExecutionEngine/JITLink/X86/ELF_external_to_absolute_conversion.s
@@ -0,0 +1,26 @@
+# RUN: llvm-mc -triple=x86_64-unknown-linux-gnu -filetype=obj -o %t %s
+# RUN: llvm-jitlink -phony-externals -noexec %t
+#
+# Check that symbol scope is demoted to local when external symbols are
+# converted to absolutes. This is demotion is necessary to avoid "unexpected
+# definition" errors.
+#
+# The reference to _GLOBAL_OFFSET_TABLE_ will trigger creation of an external
+# _GLOBAL_OFFSET_TABLE_ symbol, and the GOTOFF relocation will force creation
+# of a GOT symbol without actually introducing any GOT entries. Together these
+# should cause the external _GLOBAL_OFFSET_TABLE_ symbol to be converted to an
+# absolute symbol with address zero. If the scope is not demoted correctly this
+# will trigger an "unexpected definition" error.
+
+        .text
+	.file	"ELF_external_to_absolute_conversion.s"
+	.globl  main
+	.p2align	4, 0x90
+	.type	main, at function
+main:
+.L0$pb:
+	leaq	.L0$pb(%rip), %rax
+	movabsq	$_GLOBAL_OFFSET_TABLE_-.L0$pb, %rcx
+        movabsq $_foo at GOTOFF, %rax
+        xorq    %rax, %rax
+        retq


        


More information about the llvm-commits mailing list