From 867634862bf69ff052ffcb34f1e057d82d812b81 Mon Sep 17 00:00:00 2001 From: Andras Gemes Date: Fri, 20 Dec 2024 10:22:06 +0100 Subject: [PATCH] fix: make crt-stack position-independent --- Makefile | 2 +- lab/linux/asm-hive/x64/crt-stack.s | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index c0bc01c..f354e07 100644 --- a/Makefile +++ b/Makefile @@ -91,7 +91,7 @@ $(BUILDDIR)/linux/x64/crt-hello: lab/linux/asm-hive/x64/crt-hello.s gcc $< -fPIE -pie -g -o $@ $(BUILDDIR)/linux/x64/crt-stack: lab/linux/asm-hive/x64/crt-stack.s - gcc $< -g -o $@ + gcc $< -fPIE -pie -g -o $@ $(BUILDDIR)/linux/x64/nocrt-hello: lab/linux/asm-hive/x64/nocrt-hello.s as $< -g -o $(BUILDDIR)/linux/x64/nocrt-hello.o diff --git a/lab/linux/asm-hive/x64/crt-stack.s b/lab/linux/asm-hive/x64/crt-stack.s index c64e6dd..53a5c16 100644 --- a/lab/linux/asm-hive/x64/crt-stack.s +++ b/lab/linux/asm-hive/x64/crt-stack.s @@ -60,20 +60,20 @@ main_: mov $10, %edi mov $11, %esi call sum - mov $format_string, %edi + lea format_string(%rip), %rdi mov %eax, %esi call printf mov $10, %edi mov $11, %esi call mul - mov $format_string, %edi + lea format_string(%rip), %rdi mov %eax, %esi call printf xor %eax, %eax mov $10, %edi mov $11, %esi call calc - mov $format_string, %edi + lea format_string(%rip), %rdi mov %eax, %esi call printf pop %rbp @@ -132,20 +132,20 @@ main: mov edi, 10 mov esi, 11 call sum - mov edi, offset format_string + lea rdi, [rip + format_string] mov esi, eax call printf mov edi, 10 mov esi, 11 call mul - mov edi, offset format_string + lea rdi, [rip + format_string] mov esi, eax call printf xor eax, eax mov edi, 10 mov esi, 11 call calc - mov edi, offset format_string + lea rdi, [rip + format_string] mov esi, eax call printf pop rbp