[CRIU] [PATCH 1/2] ia32: Get rid of R_X86_64_32S relocation
Dmitry Safonov
dsafonov at virtuozzo.com
Tue Jul 25 15:35:46 MSK 2017
Distributions starts to supply GCC that is configured to compile
-pie and -fPIC code by default due to security reasons.
CONFIG_COMPAT was unfriendy to -pie by the reason of R_X86_64_32S
relocation in call32.S helper:
LINK criu/criu
/usr/bin/ld: criu/arch/x86/crtools.built-in.o: relocation R_X86_64_32S against `.text' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
make[1]: *** [criu/Makefile:92: criu/criu] Error 1
make: *** [Makefile:225: criu] Error 2
Use %rip-relative addressing to avoid ld errors for shared binary linking.
Puff, all needs to be done with bare hands!
Now CONFIG_COMPAT can be used with -pie binaries and all should
also work for debian toolchain (#315).
Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
criu/arch/x86/call32.S | 20 ++++++++++++++------
scripts/feature-tests.mak | 25 +++++++++++++++++++------
2 files changed, 33 insertions(+), 12 deletions(-)
diff --git a/criu/arch/x86/call32.S b/criu/arch/x86/call32.S
index dbed5dec3a9f..c2ddd9fc2682 100644
--- a/criu/arch/x86/call32.S
+++ b/criu/arch/x86/call32.S
@@ -39,19 +39,27 @@ ENTRY(call32_from_64)
mov %rsp,(%rdi)
mov %rdi,%rsp
+ /* Push return address and 64-bit segment descriptor */
+ sub $4, %rsp
+ movl $__USER_CS,(%rsp)
+ sub $4, %rsp
+ /* Using rip-relative addressing to get rid of R_X86_64_32S relocs */
+ leaq 2f(%rip),%r12
+ movl %r12d,(%rsp)
+
/* Switch into compatibility mode */
pushq $__USER32_CS
- pushq $1f
+ /* Using rip-relative addressing to get rid of R_X86_64_32S relocs */
+ leaq 1f(%rip), %r12
+ pushq %r12
lretq
-1:
- .code32
+1: .code32
/* Run function and switch back */
call *%esi
- jmp $__USER_CS,$1f
- .code64
+ lret
-1:
+2: .code64
/* Restore the stack */
mov (%rsp),%rsp
add $8, %rdi
diff --git a/scripts/feature-tests.mak b/scripts/feature-tests.mak
index 12bf5418102c..e39d97bb113e 100644
--- a/scripts/feature-tests.mak
+++ b/scripts/feature-tests.mak
@@ -106,17 +106,30 @@ define FEATURE_TEST_X86_COMPAT
.text
ENTRY(call32_from_64)
+ /* Push return address and 64-bit segment descriptor */
+ sub \$$4, %rsp
+ movl \$$__USER_CS,(%rsp)
+ sub \$$4, %rsp
+ /* Using rip-relative addressing to get rid of R_X86_64_32S relocs */
+ leaq 2f(%rip),%r12
+ movl %r12d,(%rsp)
+
/* Switch into compatibility mode */
pushq \$$__USER32_CS
- pushq \$$1f
+ /* Using rip-relative addressing to get rid of R_X86_64_32S relocs */
+ leaq 1f(%rip), %r12
+ pushq %r12
lretq
-1:
- .code32
+
+1: .code32
/* Run function and switch back */
call *%esi
- jmp \$$__USER_CS,\$$1f
- .code64
-1:
+ lret
+
+2: .code64
+ /* Restore the stack */
+ mov (%rsp),%rsp
+ add \$$8, %rdi
END(call32_from_64)
ENTRY(main)
--
2.13.3
More information about the CRIU
mailing list