Skip to content

Commit

Permalink
tests/hello: Add link hello-pie.c (todo)
Browse files Browse the repository at this point in the history
Try to support PIE ELF

Signed-off-by: Rong Tao <[email protected]>
  • Loading branch information
Rtoax committed Feb 26, 2024
1 parent 9de7105 commit 36c9dc1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions tests/hello/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/hello
/hello-pie
/test
/core.*
*.o
Expand Down
9 changes: 6 additions & 3 deletions tests/hello/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CFLAGS :=
CFLAGS += -O0 -ggdb -g
CFLAGS += -pthread

TARGETS := hello
TARGETS := hello hello-pie
TARGETS += test

TARGETS_ULP := patch-print.ulp
Expand All @@ -30,13 +30,16 @@ CFLAGS += -D__ULP_DEV
build: ${TARGETS_ULP} ${TARGETS}

hello: hello.o
hello-pie: hello-pie.o
test: test.o $(addsuffix .o, $(basename $(TARGETS_ULP)))

CFLAGS_hello := -g -ggdb -flto -pthread
CFLAGS_hello-pie := ${CFLAGS_hello} -fpie
LDFLAGS_hello-pie := -pie

%.o: %.c
@echo -e "Compile \033[1m$(<)\033[m to \033[1m$(@)\033[m"
$(CC) $(CFLAGS) $(CFLAGS_$(*)) -o $(@) -c $(<)
$(CC) -o $(@) -c $(<) $(CFLAGS) $(CFLAGS_$(*))

%.ulp: %.o
@echo -e "Gen ulpatch \033[1m$(<)\033[m to \033[1m$(@)\033[m"
Expand All @@ -45,7 +48,7 @@ CFLAGS_hello := -g -ggdb -flto -pthread

$(TARGETS): %:
@echo -e "Target \033[1;32m$(@)\033[m"
$(CC) $(CFLAGS) $(CFLAGS_$(*)) -o $(@) $(^) $(LDLIBS) $(LDFLAGS) $(LDFLAGS_$(*))
$(CC) -o $(@) $(^) $(LDLIBS) $(LDFLAGS) $(LDFLAGS_$(*)) $(CFLAGS) $(CFLAGS_$(*))
strip $(@) -o $(@).stripped

clean:
Expand Down
1 change: 1 addition & 0 deletions tests/hello/hello-pie.c
3 changes: 2 additions & 1 deletion tests/hello/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ while true; do
done

[[ -z ${pid} ]] && pid=$(pidof hello || true)
[[ -z ${pid} ]] && echo "ERROR: Run ./hello first or specify -p" && exit 1
[[ -z ${pid} ]] && pid=$(pidof hello-pie || true)
[[ -z ${pid} ]] && echo "ERROR: Run ./hello or ./hello-pie first or specify -p" && exit 1

[[ -z ${patch} ]] && echo "ERROR: Must specify ulpatch with -u" && exit 1
[[ ! -e ${patch} ]] && echo "ERROR: ${patch} is not exist." && exit 1
Expand Down

0 comments on commit 36c9dc1

Please sign in to comment.