Skip to content

Commit

Permalink
tests/hello: Patches and executables are compiled separately
Browse files Browse the repository at this point in the history
And ULP_PIC macros are added.

TODO: If enable ULP_PIC, segvfault when apply ulpatch, i guess there are
some relocation handle failed.

Signed-off-by: Rong Tao <[email protected]>
  • Loading branch information
Rtoax committed Mar 2, 2024
1 parent 5c830ad commit f6ff7e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cmake_install.cmake
# Patches
*.patch
*.ulp
*.ulpo
*.up

# Temp
Expand Down
23 changes: 16 additions & 7 deletions tests/hello/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ endif
CFLAGS :=
CFLAGS += -O0 -ggdb -g
CFLAGS += -pthread
CFLAGS += -D__ULP_DEV
ifdef MCOUNT
CFLAGS += -pg
endif

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

TARGETS_ULP := patch-print.ulp
Expand All @@ -25,10 +30,10 @@ TARGETS_ULP += patch-add-vars.ulp
TARGETS_ULP += patch-failed-bss.ulp
TARGETS_ULP += patch-pthread.ulp

CFLAGS += -D__ULP_DEV

ifdef MCOUNT
CFLAGS += -pg
CFLAGS_ULP :=
CFLAGS_ULP += -O0
ifdef ULP_PIC
CFLAGS_ULP += -fpic
endif

build: ${TARGETS_ULP} ${TARGETS}
Expand All @@ -45,7 +50,11 @@ LDFLAGS_hello-pie := -pie
@echo -e "Compile \033[1m$(<)\033[m to \033[1m$(@)\033[m"
$(CC) -o $(@) -c $(<) $(CFLAGS) $(CFLAGS_$(*))

%.ulp: %.o
%.ulpo: %.c
@echo -e "Compile \033[1m$(<)\033[m to \033[1m$(@)\033[m"
$(CC) -o $(@) -c $(<) $(CFLAGS_ULP)

%.ulp: %.ulpo
@echo -e "Gen ulpatch \033[1m$(<)\033[m to \033[1m$(@)\033[m"
cp $(<) $(@).no-build-id
$(LD) -relocatable -o $(@) --build-id=sha1 $(<)
Expand All @@ -56,4 +65,4 @@ $(TARGETS): %:
strip $(@) -o $(@).stripped

clean:
rm -f $(TARGETS) *.o *.ulp core.* *.ulp.no-build-id *.stripped
rm -f $(TARGETS) *.o *.ulp *.ulpo core.* *.ulp.no-build-id *.stripped

0 comments on commit f6ff7e3

Please sign in to comment.