summaryrefslogtreecommitdiff
path: root/test/ELF/got32x-i386.s
diff options
context:
space:
mode:
Diffstat (limited to 'test/ELF/got32x-i386.s')
-rw-r--r--test/ELF/got32x-i386.s47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/ELF/got32x-i386.s b/test/ELF/got32x-i386.s
new file mode 100644
index 000000000000..9a67d1997f2b
--- /dev/null
+++ b/test/ELF/got32x-i386.s
@@ -0,0 +1,47 @@
+# REQUIRES: x86
+
+## i386-got32x-baseless.elf is a file produced using GNU as v.2.27
+## using following code and command line:
+## (as --32 -o base.o base.s)
+##
+## .text
+## .globl foo
+## .type foo, @function
+## foo:
+## nop
+##
+## _start:
+## movl foo@GOT, %eax
+## movl foo@GOT, %ebx
+## movl foo@GOT(%eax), %eax
+## movl foo@GOT(%ebx), %eax
+##
+## Result file contains four R_386_GOT32X relocations. Generated code
+## is also a four mov instructions. And first two has no base register:
+## <_start>:
+## 1: 8b 05 00 00 00 00 mov 0x0,%eax
+## 7: 8b 1d 00 00 00 00 mov 0x0,%ebx
+## d: 8b 80 00 00 00 00 mov 0x0(%eax),%eax
+## 13: 8b 83 00 00 00 00 mov 0x0(%ebx),%eax
+##
+## R_386_GOT32X is computed as G + A - GOT, but if it used without base
+## register, it should be calculated as G + A. Using without base register
+## is only allowed for non-PIC code.
+##
+# RUN: ld.lld %S/Inputs/i386-got32x-baseless.elf -o %t1
+# RUN: llvm-objdump -section-headers -d %t1 | FileCheck %s
+
+## 73728 == 0x12000 == ADDR(.got)
+# CHECK: _start:
+# CHECK-NEXT: 11001: 8b 05 {{.*}} movl 73728, %eax
+# CHECK-NEXT: 11007: 8b 1d {{.*}} movl 73728, %ebx
+# CHECK-NEXT: 1100d: 8b 80 {{.*}} movl -4(%eax), %eax
+# CHECK-NEXT: 11013: 8b 83 {{.*}} movl -4(%ebx), %eax
+# CHECK: Sections:
+# CHECK: Name Size Address
+# CHECK: .got 00000004 0000000000012000
+
+# RUN: not ld.lld %S/Inputs/i386-got32x-baseless.elf -o %t1 -pie 2>&1 | \
+# RUN: FileCheck %s --check-prefix=ERR
+# ERR: relocation R_386_GOT32X against 'foo' without base register can not be used when PIC enabled
+# ERR: relocation R_386_GOT32X against 'foo' without base register can not be used when PIC enabled