[llvm] cb19b83 - [RuntimeDyld][ELF] Fixed relocations referencing undefined TLS symbols

Moritz Sichert via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 8 08:50:56 PST 2023


Author: Moritz Sichert
Date: 2023-02-08T17:49:53+01:00
New Revision: cb19b83baac1a204cb61e7fd7c8f22dac886ce39

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

LOG: [RuntimeDyld][ELF] Fixed relocations referencing undefined TLS symbols

The classification of TLS symbols in ELF was changed from ST_Data to
ST_Other in the following commit:
018a484cd26d72fb4c9e7fd75e5f5bc7838dfc73

RuntimeDyldELF::processRelocationRef() needs to be updated to also
handle ST_Other symbols so that it handles TLS relocations correctly.
The current tests did not fail because we have a shortcut for global
symbols that are already defined.

Differential Revision: https://reviews.llvm.org/D143568

Added: 
    

Modified: 
    llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
    llvm/test/ExecutionEngine/RuntimeDyld/X86/TLS.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
index b9ab127563d9b..3c7f4ec47eb84 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
@@ -1282,6 +1282,7 @@ RuntimeDyldELF::processRelocationRef(
     }
     case SymbolRef::ST_Data:
     case SymbolRef::ST_Function:
+    case SymbolRef::ST_Other:
     case SymbolRef::ST_Unknown: {
       Value.SymbolName = TargetName.data();
       Value.Addend = Addend;

diff  --git a/llvm/test/ExecutionEngine/RuntimeDyld/X86/TLS.s b/llvm/test/ExecutionEngine/RuntimeDyld/X86/TLS.s
index ed88b5491d077..2b10592489782 100644
--- a/llvm/test/ExecutionEngine/RuntimeDyld/X86/TLS.s
+++ b/llvm/test/ExecutionEngine/RuntimeDyld/X86/TLS.s
@@ -1,8 +1,11 @@
 # REQUIRES: x86_64-linux
 # RUN: rm -rf %t && mkdir -p %t
-# RUN: llvm-mc -triple=x86_64-unknown-linux -filetype=obj -o %t/tls.o %s
-# RUN: llvm-rtdyld -triple=x86_64-unknown-linux -execute %t/tls.o
+# RUN: split-file %s %t
+# RUN: llvm-mc -triple=x86_64-unknown-linux -filetype=obj -o %t/test_runner.o %t/test_runner.s
+# RUN: llvm-mc -triple=x86_64-unknown-linux -filetype=obj -o %t/external_tls.o %t/external_tls.s
+# RUN: llvm-rtdyld -triple=x86_64-unknown-linux -execute %t/test_runner.o %t/external_tls.o
 
+#--- test_runner.s
 
 _main:
 
@@ -130,6 +133,28 @@ _main:
 	jmp 2f
 1:
 
+# External TLS variable, Local Exec TLS Model (small code model)
+	mov %fs:external_tls_var at tpoff, %eax
+	cmp $0x56, %eax
+	je 1f
+	mov $12, %eax
+	jmp 2f
+1:
+
+# External TLS variable, Global Dynamic TLS Model (small code model)
+	.byte 0x66
+	leaq external_tls_var at tlsgd(%rip), %rdi
+	.byte 0x66, 0x66, 0x48
+	call __tls_get_addr at plt
+	mov (%rax), %eax
+	cmp $0x56, %eax
+	je 1f
+	mov $13, %eax
+	jmp 2f
+1:
+
+
+# Return 0 if all tests are successful
 	xor %eax, %eax
 
 2:
@@ -152,3 +177,14 @@ tls_foo:
 	.align 4
 tls_bar:
 	.long 0x34
+
+#--- external_tls.s
+
+	.section .tdata, "awT", @progbits
+
+	.global external_tls_var
+	.type external_tls_var, @object
+	.size external_tls_var, 4
+	.align 4
+external_tls_var:
+	.long 0x56


        


More information about the llvm-commits mailing list