From 162c84cfe6b4652bae213776944b910390553d41 Mon Sep 17 00:00:00 2001
From: Marvin Borner
Date: Sat, 15 Aug 2020 13:45:41 +0200
Subject: Reverted PIE binaries and fixed userspace lib

---
 apps/Makefile | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

(limited to 'apps/Makefile')

diff --git a/apps/Makefile b/apps/Makefile
index 5a6ec67..7678a0b 100644
--- a/apps/Makefile
+++ b/apps/Makefile
@@ -3,15 +3,22 @@
 COBJS = a.o b.o init.o
 CC = ../cross/opt/bin/i686-elf-gcc
 LD = ../cross/opt/bin/i686-elf-ld
+OC = ../cross/opt/bin/i686-elf-objcopy
 
 # Flags to make the binary smaller TODO: Remove after indirect pointer support!
 CSFLAGS = -mpreferred-stack-boundary=2 -fno-asynchronous-unwind-tables -Os
 
-CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Wl,-emain -I../lib/inc/ -Duserspace
+CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -ffunction-sections -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Wl,-emain -I../lib/inc/ -Wl,-emain -fPIE -Duserspace
 
 all: $(COBJS)
 
 %.o: %.c
 	@mkdir -p ../build/apps/
 	@$(CC) -c $(CFLAGS) $< -o $@
-	@$(CC) -r $(CFLAGS) -o ../build/apps/$(@:.o=) -L../build $< -lc
+	@$(LD) -o $(@:.o=.elf) -Tlink.ld -L../build/ $@ -lc
+	@$(OC) -O binary $(@:.o=.elf) ../build/apps/$(@:.o=)
+
+# %.o: %.c
+# 	@mkdir -p ../build/apps/
+# 	@$(CC) -c $(CFLAGS) $< -o $@
+# 	@$(CC) -r $(CFLAGS) -o ../build/apps/$(@:.o=) -L../build $< -lc
-- 
cgit v1.2.3