[PATCH] D154777: [LLD] [COFF] Warn about pseudo relocations that are too narrow
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 11 13:43:46 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6daa4b90e28e: [LLD] [COFF] Warn about pseudo relocations that are too narrow (authored by mstorsjo).
Changed prior to commit:
https://reviews.llvm.org/D154777?vs=538801&id=539282#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154777/new/
https://reviews.llvm.org/D154777
Files:
lld/COFF/Chunks.cpp
lld/test/CMakeLists.txt
lld/test/COFF/autoimport-nowarn.s
lld/test/COFF/autoimport-warn.s
Index: lld/test/COFF/autoimport-warn.s
===================================================================
--- /dev/null
+++ lld/test/COFF/autoimport-warn.s
@@ -0,0 +1,29 @@
+# REQUIRES: x86
+
+# RUN: echo -e "EXPORTS\nvariable1 DATA\nvariable2 DATA" > %t-lib.def
+# RUN: llvm-dlltool -m i386:x86-64 -d %t-lib.def -D lib.dll -l %t-lib.lib
+
+# RUN: llvm-mc -triple=x86_64-windows-gnu %s -filetype=obj -o %t.obj
+# RUN: lld-link -lldmingw -out:%t.exe -entry:main %t.obj %t-lib.lib -verbose 2>&1 | FileCheck %s
+
+# CHECK-NOT: runtime pseudo relocation {{.*}} against symbol variable1
+# CHECK: warning: runtime pseudo relocation in {{.*}}.obj against symbol variable2 is too narrow (only 32 bits wide); this can fail at runtime depending on memory layout
+# CHECK-NOT: runtime pseudo relocation {{.*}} against symbol variable1
+
+ .global main
+ .text
+main:
+ movq .refptr.variable1(%rip), %rax
+ movl (%rax), %eax
+ movl variable2(%rip), %ecx
+ addl %ecx, %eax
+ ret
+
+ .section .rdata$.refptr.variable1,"dr",discard,.refptr.variable1
+ .global .refptr.variable1
+.refptr.variable1:
+ .quad variable1
+
+relocs:
+ .quad __RUNTIME_PSEUDO_RELOC_LIST__
+ .quad __RUNTIME_PSEUDO_RELOC_LIST_END__
Index: lld/test/COFF/autoimport-nowarn.s
===================================================================
--- /dev/null
+++ lld/test/COFF/autoimport-nowarn.s
@@ -0,0 +1,19 @@
+# REQUIRES: x86
+
+# RUN: echo -e "EXPORTS\nvariable" > %t-lib.def
+# RUN: llvm-dlltool -m i386 -d %t-lib.def -D lib.dll -l %t-lib.lib
+
+# RUN: llvm-mc -triple=i386-windows-gnu %s -filetype=obj -o %t.obj
+# RUN: lld-link -lldmingw -out:%t.exe -entry:main %t.obj %t-lib.lib -verbose 2>&1 | FileCheck --allow-empty %s
+
+# CHECK-NOT: runtime pseudo relocation {{.*}} is too narrow
+
+ .global _main
+ .text
+_main:
+ movl _variable, %eax
+ ret
+
+relocs:
+ .long ___RUNTIME_PSEUDO_RELOC_LIST__
+ .long ___RUNTIME_PSEUDO_RELOC_LIST_END__
Index: lld/test/CMakeLists.txt
===================================================================
--- lld/test/CMakeLists.txt
+++ lld/test/CMakeLists.txt
@@ -51,6 +51,7 @@
llvm-config
llvm-cvtres
llvm-dis
+ llvm-dlltool
llvm-dwarfdump
llvm-lib
llvm-lipo
Index: lld/COFF/Chunks.cpp
===================================================================
--- lld/COFF/Chunks.cpp
+++ lld/COFF/Chunks.cpp
@@ -661,6 +661,13 @@
toString(file));
continue;
}
+ int addressSizeInBits = file->ctx.config.is64() ? 64 : 32;
+ if (sizeInBits < addressSizeInBits) {
+ warn("runtime pseudo relocation in " + toString(file) + " against " +
+ "symbol " + target->getName() + " is too narrow (only " +
+ Twine(sizeInBits) + " bits wide); this can fail at runtime " +
+ "depending on memory layout");
+ }
// sizeInBits is used to initialize the Flags field; currently no
// other flags are defined.
res.emplace_back(target, this, rel.VirtualAddress, sizeInBits);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154777.539282.patch
Type: text/x-patch
Size: 3021 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230711/1c2c4c80/attachment.bin>
More information about the llvm-commits
mailing list