Created
April 26, 2024 19:48
-
-
Save 8dcc/0fe08d85255b374fed28497b2dbfb39a to your computer and use it in GitHub Desktop.
Assembly PIC test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
/* Assembly function, calls foo() */ | |
extern int foo_proxy(int a, int b); | |
int myGlobalInteger = 0; | |
int foo(int a, int b) { | |
return a + b; | |
} | |
int main(void) { | |
int result = foo_proxy(5, 6); | |
printf("result: %d\n", result); | |
printf("global: %d\n", myGlobalInteger); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC=gcc | |
CFLAGS=-Wall -Wextra -Ofast -fPIC | |
LDFLAGS= | |
AS=nasm | |
ASFLAGS=-f elf64 | |
.PHONY: all clean | |
all: asm-pic-test.out | |
clean: | |
rm -f asm-pic-test.out main.o test.o | |
asm-pic-test.out: main.o test.o | |
$(CC) $(CFLAGS) -shared -o $@ $^ $(LDFLAGS) | |
main.o: main.c | |
$(CC) $(CFLAGS) -c -o $@ $< | |
test.o: test.asm | |
$(AS) $(ASFLAGS) -o $@ $< |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Same output with and without this line | |
default REL | |
section .text | |
extern myGlobalInteger | |
extern foo | |
global foo_proxy | |
foo_proxy: | |
mov [myGlobalInteger], rdi | |
jmp foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment