Skip to content

Commit 0a3c299

Browse files
committed
Support a make/make-install build system
This implements a more traditional build system: $ make $ make install This version will also use the system elfutils and dynamic linking, rather than the contrib/ version and static linking. This version will still statically link a specific version of zydis to ensure consistent matching/patching language behaviour. The old build.sh and install.sh scripts are still supported, and are the main way of building the "official" binary release. This menthod uses static linking, so the binaries will run on most Linux distributions without dependency issues. See #74
1 parent bae1d39 commit 0a3c299

File tree

6 files changed

+152
-119
lines changed

6 files changed

+152
-119
lines changed

Makefile

Lines changed: 111 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#CC=clang
2-
#CXX=clang++
1+
#########################################################################
2+
# BUILD COMMON
3+
#########################################################################
34

45
CXXFLAGS = -std=c++11 -Wall -Wno-reorder -fPIC -pie -march=native \
56
-DVERSION=$(shell cat VERSION) -Wl,-rpath=/usr/share/e9tool/lib/
@@ -38,44 +39,32 @@ E9TOOL_LIBS=\
3839
contrib/libdw/libdw.a
3940
E9TOOL_CXXFLAGS=\
4041
-I src/e9tool/ -Wno-unused-function \
41-
-I contrib/libdw/ \
4242
-I contrib/zydis/include/ \
4343
-I contrib/zydis/dependencies/zycore/include/
4444
E9TOOL_LDFLAGS=\
4545
-Wl,--dynamic-list=src/e9tool/e9tool.syms \
46-
-lpthread -ldl -lz
46+
-ldl -lz
4747

48-
release: CXXFLAGS += -O2 -D NDEBUG
49-
release: $(E9PATCH_OBJS)
50-
$(CXX) $(CXXFLAGS) $(E9PATCH_OBJS) -o e9patch
51-
strip e9patch
48+
#########################################################################
49+
# CONVENTIONAL BUILD
50+
#########################################################################
5251

53-
debug: CXXFLAGS += -O0 -g
54-
debug: $(E9PATCH_OBJS)
55-
$(CXX) $(CXXFLAGS) $(E9PATCH_OBJS) -o e9patch
52+
all: e9tool e9patch
5653

57-
sanitize: CXXFLAGS += -O0 -g -fsanitize=address
58-
sanitize: $(E9PATCH_OBJS)
59-
$(CXX) $(CXXFLAGS) $(E9PATCH_OBJS) -o e9patch
60-
61-
tool: CXXFLAGS += -O2 $(E9TOOL_CXXFLAGS)
62-
tool: $(E9TOOL_OBJS) $(E9TOOL_LIBS)
63-
$(CXX) $(CXXFLAGS) $(E9TOOL_OBJS) $(E9TOOL_LIBS) -o e9tool \
64-
$(E9TOOL_LDFLAGS) -Wl,-Map=output.map
54+
e9tool: CXXFLAGS += -O2 -DSYSTEM_LIBDW $(E9TOOL_CXXFLAGS)
55+
e9tool: contrib/zydis/libZydis.a $(E9TOOL_OBJS)
56+
$(CXX) $(CXXFLAGS) $(E9TOOL_OBJS) contrib/zydis/libZydis.a -o e9tool \
57+
$(E9TOOL_LDFLAGS) -ldw
6558
strip e9tool
6659

67-
tool.debug: CXXFLAGS += -O0 -g $(E9TOOL_CXXFLAGS)
68-
tool.debug: $(E9TOOL_OBJS) $(E9TOOL_LIBS)
69-
$(CXX) $(CXXFLAGS) $(E9TOOL_OBJS) $(E9TOOL_LIBS) -o e9tool \
70-
$(E9TOOL_LDFLAGS)
71-
72-
tool.sanitize: CXXFLAGS += -O0 -g -fsanitize=address $(E9TOOL_CXXFLAGS)
73-
tool.sanitize: $(E9TOOL_OBJS) $(E9TOOL_LIBS)
74-
$(CXX) $(CXXFLAGS) $(E9TOOL_OBJS) $(E9TOOL_LIBS) -o e9tool \
75-
$(E9TOOL_LDFLAGS)
60+
e9patch: CXXFLAGS += -O2
61+
e9patch: $(E9PATCH_OBJS)
62+
$(CXX) $(CXXFLAGS) $(E9PATCH_OBJS) -o e9patch
63+
strip e9patch
7664

77-
tool.clean:
78-
rm -rf $(E9TOOL_OBJS) e9tool
65+
clean:
66+
rm -rf $(E9PATCH_OBJS) $(E9TOOL_OBJS) e9patch e9tool \
67+
src/e9patch/e9loader.c e9loader.out e9loader.o e9loader.bin
7968

8069
loader_elf:
8170
$(CXX) -std=c++11 -Wall -fno-stack-protector -Wno-unused-function -fPIC \
@@ -99,7 +88,96 @@ contrib/zydis/libZydis.a:
9988
contrib/libdw/libdw.a:
10089
(cd contrib/libdw/; make)
10190

102-
clean:
103-
rm -rf $(E9PATCH_OBJS) e9patch \
104-
src/e9patch/e9loader.c e9loader.out e9loader.o e9loader.bin
91+
install: all
92+
install -d "$(DESTDIR)/usr/bin"
93+
install -m 755 e9patch "$(DESTDIR)/usr/bin/e9patch"
94+
install -m 755 e9tool "$(DESTDIR)/usr/bin/e9tool"
95+
install -m 755 e9compile.sh "$(DESTDIR)/usr/bin/e9compile"
96+
sed \
97+
-e 's/-I example/-I \/usr\/share\/e9compile\/include/g' e9compile.sh > \
98+
"$(DESTDIR)/usr/bin/e9compile"
99+
chmod 555 "$(DESTDIR)/usr/bin/e9compile"
100+
install -d "$(DESTDIR)/usr/share/doc/e9patch/"
101+
sed \
102+
-e 's/https:\/\/github.com\/GJDuck\/e9patch\/blob\/master\/doc\/e9tool-user-guide.md/file:\/\/\/usr\/share\/doc\/e9tool\/e9tool-user-guide.html/g' \
103+
-e 's/https:\/\/github.com\/GJDuck\/e9patch\/tree\/master\/examples/file:\/\/\/usr\/share\/e9tool\/examples/g' \
104+
doc/e9patch-programming-guide.md | markdown > \
105+
"$(DESTDIR)/usr/share/doc/e9patch/e9patch-programming-guide.html"
106+
install -m 444 LICENSE "$(DESTDIR)/usr/share/doc/e9patch/LICENSE"
107+
install -d "$(DESTDIR)/usr/share/doc/e9tool/"
108+
sed \
109+
-e 's/https:\/\/github.com\/GJDuck\/e9patch\/blob\/master\/doc\/e9patch-programming-guide.md/file:\/\/\/usr\/share\/doc\/e9patch\/e9patch-programming-guide.html/g' \
110+
doc/e9tool-user-guide.md | markdown > \
111+
"$(DESTDIR)/usr/share/doc/e9tool/e9tool-user-guide.html"
112+
install -m 444 LICENSE "$(DESTDIR)/usr/share/doc/e9tool/LICENSE"
113+
install -d "$(DESTDIR)/usr/share/e9tool/include/"
114+
install -m 444 src/e9tool/e9tool.h "$(DESTDIR)/usr/share/e9tool/include/e9tool.h"
115+
install -m 444 src/e9tool/e9plugin.h "$(DESTDIR)/usr/share/e9tool/include/e9plugin.h"
116+
install -d "$(DESTDIR)/usr/share/e9tool/examples/"
117+
install -m 444 examples/bounds.c "$(DESTDIR)/usr/share/e9tool/examples/bounds.c"
118+
sed \
119+
-e 's/.\/e9compile.sh examples\/bounds.c/e9compile \/usr\/share\/e9tool\/examples\/bounds.c/' \
120+
-e 's/\.\/e9tool/e9tool/' \
121+
examples/bounds.sh > \
122+
"$(DESTDIR)/usr/share/e9tool/examples/bounds.sh"
123+
chmod 555 "$(DESTDIR)/usr/share/e9tool/examples/bounds.sh"
124+
install -m 444 examples/cfi.c "$(DESTDIR)/usr/share/e9tool/examples/cfi.c"
125+
install -m 444 examples/count.c "$(DESTDIR)/usr/share/e9tool/examples/count.c"
126+
install -m 444 examples/cov.c "$(DESTDIR)/usr/share/e9tool/examples/cov.c"
127+
install -m 444 examples/delay.c "$(DESTDIR)/usr/share/e9tool/examples/delay.c"
128+
install -m 444 examples/hello.c "$(DESTDIR)/usr/share/e9tool/examples/hello.c"
129+
install -m 444 examples/limit.c "$(DESTDIR)/usr/share/e9tool/examples/limit.c"
130+
install -m 444 examples/nop.c "$(DESTDIR)/usr/share/e9tool/examples/nop.c"
131+
install -m 444 examples/print.c "$(DESTDIR)/usr/share/e9tool/examples/print.c"
132+
install -m 444 examples/printf.c "$(DESTDIR)/usr/share/e9tool/examples/printf.c"
133+
install -m 444 examples/skip.c "$(DESTDIR)/usr/share/e9tool/examples/skip.c"
134+
install -m 444 examples/state.c "$(DESTDIR)/usr/share/e9tool/examples/state.c"
135+
install -m 444 examples/trap.c "$(DESTDIR)/usr/share/e9tool/examples/trap.c"
136+
install -m 444 examples/win64_demo.c "$(DESTDIR)/usr/share/e9tool/examples/win64_demo.c"
137+
install -d "$(DESTDIR)/usr/share/e9tool/examples/plugins/"
138+
install -m 444 examples/plugins/example.cpp "$(DESTDIR)/usr/share/e9tool/examples/plugins/example.cpp"
139+
install -d "$(DESTDIR)/usr/share/e9compile/include/"
140+
install -m 444 examples/stdlib.c "$(DESTDIR)/usr/share/e9compile/include/stdlib.c"
141+
install -m 444 src/e9patch/e9loader.h "$(DESTDIR)/usr/share/e9compile/include/e9loader.h"
142+
install -d "$(DESTDIR)/usr/share/man/man1/"
143+
gzip --stdout doc/e9patch.1 > "$(DESTDIR)/usr/share/man/man1/e9patch.1.gz"
144+
chmod 444 "$(DESTDIR)/usr/share/man/man1/e9patch.1.gz"
145+
gzip --stdout doc/e9tool.1 > "$(DESTDIR)/usr/share/man/man1/e9tool.1.gz"
146+
chmod 444 "$(DESTDIR)/usr/share/man/man1/e9tool.1.gz"
147+
gzip --stdout doc/e9compile.1 > "$(DESTDIR)/usr/share/man/man1/e9compile.1.gz"
148+
chmod 444 "$(DESTDIR)/usr/share/man/man1/e9compile.1.gz"
149+
150+
#########################################################################
151+
# SPECIAL BUILD
152+
#########################################################################
153+
154+
release: CXXFLAGS += -O2 -D NDEBUG
155+
release: $(E9PATCH_OBJS)
156+
$(CXX) $(CXXFLAGS) $(E9PATCH_OBJS) -o e9patch
157+
strip e9patch
158+
159+
debug: CXXFLAGS += -O0 -g
160+
debug: $(E9PATCH_OBJS)
161+
$(CXX) $(CXXFLAGS) $(E9PATCH_OBJS) -o e9patch
162+
163+
sanitize: CXXFLAGS += -O0 -g -fsanitize=address
164+
sanitize: $(E9PATCH_OBJS)
165+
$(CXX) $(CXXFLAGS) $(E9PATCH_OBJS) -o e9patch
166+
167+
tool: CXXFLAGS += -O2 $(E9TOOL_CXXFLAGS) -I contrib/libdw/
168+
tool: $(E9TOOL_OBJS) $(E9TOOL_LIBS)
169+
$(CXX) $(CXXFLAGS) $(E9TOOL_OBJS) $(E9TOOL_LIBS) -o e9tool \
170+
$(E9TOOL_LDFLAGS)
171+
strip e9tool
172+
173+
tool.debug: CXXFLAGS += -O0 -g $(E9TOOL_CXXFLAGS) -I contrib/libdw/
174+
tool.debug: $(E9TOOL_OBJS) $(E9TOOL_LIBS)
175+
$(CXX) $(CXXFLAGS) $(E9TOOL_OBJS) $(E9TOOL_LIBS) -o e9tool \
176+
$(E9TOOL_LDFLAGS)
177+
178+
tool.sanitize: CXXFLAGS += -O0 -g -fsanitize=address $(E9TOOL_CXXFLAGS) \
179+
-I contrib/libdw/
180+
tool.sanitize: $(E9TOOL_OBJS) $(E9TOOL_LIBS)
181+
$(CXX) $(CXXFLAGS) $(E9TOOL_OBJS) $(E9TOOL_LIBS) -o e9tool \
182+
$(E9TOOL_LDFLAGS)
105183

build.sh

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,10 @@ else
1515
OFF=
1616
fi
1717

18-
while [ $# -ge 1 ]
19-
do
20-
case "$1" in
21-
--help|-h)
22-
echo "usage: $0 [OPTIONS]"
23-
echo
24-
echo "OPTIONS:"
25-
echo
26-
echo " --help, -h"
27-
echo " Print this message"
28-
echo
29-
exit 0
30-
;;
31-
*)
32-
echo "unknown argument \"$1\"; try \`$0 --help' for more information"
33-
exit 1
34-
;;
35-
esac
36-
shift
37-
done
38-
3918
echo -e "${GREEN}$0${OFF}: building e9patch and e9tool..."
40-
make tool.clean clean
19+
(cd contrib/libdw; make clean; make -j `nproc`)
20+
(cd contrib/zydis; make clean; make -j `nproc`)
21+
make clean
4122
make -j `nproc` tool release
4223

4324
echo -e "${GREEN}$0${OFF}: done...!"

contrib/libdw/elf_version.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
#include <libelfP.h>
3535
#include <pthread.h>
3636

37-
/* Multiple threads may initialize __libelf_version.
38-
pthread_once() ensures that __libelf_version is initialized only once. */
39-
once_define(static, version_once);
40-
4137
/* Currently selected version. Should be EV_CURRENT.
4238
Will be EV_NONE if elf_version () has not been called yet. */
4339
unsigned int __libelf_version = EV_NONE;
@@ -58,7 +54,7 @@ elf_version (unsigned int version)
5854
/* Phew, we know this version. */
5955

6056
/* Signal that the version is now initialized. */
61-
once(version_once, initialize_version);
57+
initialize_version();
6258

6359
/* And return the last (or initial) version. */
6460
return EV_CURRENT;

contrib/libdw/libdw_alloc.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,30 @@ __libdw_oom (void)
154154
while (1)
155155
error (EXIT_FAILURE, ENOMEM, "libdw");
156156
}
157+
158+
int pthread_rwlock_init(pthread_rwlock_t *restrict rwlock,
159+
const pthread_rwlockattr_t *restrict attr)
160+
{
161+
return 0;
162+
}
163+
int pthread_rwlock_rdlock(pthread_rwlock_t *lock)
164+
{
165+
return 0;
166+
}
167+
int pthread_rwlock_tryrdlock(pthread_rwlock_t *lock)
168+
{
169+
return 0;
170+
}
171+
int pthread_rwlock_wrlock(pthread_rwlock_t *lock)
172+
{
173+
return 0;
174+
}
175+
int pthread_rwlock_unlock(pthread_rwlock_t *lock)
176+
{
177+
return 0;
178+
}
179+
int pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
180+
{
181+
return 0;
182+
}
183+

install.sh

Lines changed: 6 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -33,70 +33,17 @@ fi
3333
NAME=e9patch
3434
VERSION=`cat VERSION`
3535

36-
if [ ! -x e9patch ]
37-
then
38-
echo -e "${RED}$0${OFF}: run ./build.sh first" 1>&2
39-
exit 1
40-
fi
41-
4236
set -e
4337

38+
./build.sh
4439
rm -rf install/
4540
mkdir -p install
46-
cd install/
47-
mkdir -p data
48-
mkdir -p control
41+
mkdir -p install/data
42+
mkdir -p install/control
43+
44+
DESTDIR=install/data make install
4945

50-
cd data/
51-
mkdir -p "./usr/bin/"
52-
cp "../../e9patch" "./usr/bin/"
53-
cp "../../e9tool" "./usr/bin/"
54-
cat "../../e9compile.sh" | \
55-
sed 's/-I examples/-I \/usr\/share\/e9compile\/include/g' > \
56-
"./usr/bin/e9compile"
57-
chmod a+x "./usr/bin/e9compile"
58-
mkdir -p "./usr/share/doc/e9patch/"
59-
cat "../../doc/e9patch-programming-guide.md" | \
60-
sed 's/https:\/\/github.com\/GJDuck\/e9patch\/blob\/master\/doc\/e9tool-user-guide.md/file:\/\/\/usr\/share\/doc\/e9tool\/e9tool-user-guide.html/g' | \
61-
sed 's/https:\/\/github.com\/GJDuck\/e9patch\/tree\/master\/examples/file:\/\/\/usr\/share\/e9tool\/examples/g' | \
62-
markdown > "./usr/share/doc/e9patch/e9patch-programming-guide.html"
63-
cp "../../LICENSE" "./usr/share/doc/e9patch/"
64-
mkdir -p "./usr/share/doc/e9tool/"
65-
cat "../../doc/e9tool-user-guide.md" | \
66-
sed 's/https:\/\/github.com\/GJDuck\/e9patch\/blob\/master\/doc\/e9patch-programming-guide.md/file:\/\/\/usr\/share\/doc\/e9patch\/e9patch-programming-guide.html/g' | \
67-
markdown > "./usr/share/doc/e9tool/e9tool-user-guide.html"
68-
cp "../../LICENSE" "./usr/share/doc/e9tool/"
69-
mkdir -p "./usr/share/e9tool/include/"
70-
cp "../../src/e9tool/e9tool.h" "./usr/share/e9tool/include/"
71-
cp "../../src/e9tool/e9plugin.h" "./usr/share/e9tool/include/"
72-
mkdir -p "./usr/share/e9tool/examples/"
73-
cp "../../examples/bounds.c" "./usr/share/e9tool/examples/"
74-
cat "../../examples/bounds.sh" | \
75-
sed 's/.\/e9compile.sh examples\/bounds.c/e9compile \/usr\/share\/e9tool\/examples\/bounds.c/' | \
76-
sed 's/\.\/e9tool/e9tool/' > "./usr/share/e9tool/examples/bounds.sh"
77-
chmod a+x "./usr/share/e9tool/examples/bounds.sh"
78-
cp "../../examples/cfi.c" "./usr/share/e9tool/examples/"
79-
cp "../../examples/count.c" "./usr/share/e9tool/examples/"
80-
cp "../../examples/cov.c" "./usr/share/e9tool/examples/"
81-
cp "../../examples/delay.c" "./usr/share/e9tool/examples/"
82-
cp "../../examples/hello.c" "./usr/share/e9tool/examples/"
83-
cp "../../examples/limit.c" "./usr/share/e9tool/examples/"
84-
cp "../../examples/nop.c" "./usr/share/e9tool/examples/"
85-
cp "../../examples/print.c" "./usr/share/e9tool/examples/"
86-
cp "../../examples/printf.c" "./usr/share/e9tool/examples/"
87-
cp "../../examples/skip.c" "./usr/share/e9tool/examples/"
88-
cp "../../examples/state.c" "./usr/share/e9tool/examples/"
89-
cp "../../examples/trap.c" "./usr/share/e9tool/examples/"
90-
cp "../../examples/win64_demo.c" "./usr/share/e9tool/examples/"
91-
mkdir -p "./usr/share/e9tool/examples/plugins/"
92-
cp "../../examples/plugins/example.cpp" "./usr/share/e9tool/examples/plugins/"
93-
mkdir -p "./usr/share/e9compile/include/"
94-
cp "../../examples/stdlib.c" "./usr/share/e9compile/include/"
95-
cp "../../src/e9patch/e9loader.h" "./usr/share/e9compile/include/"
96-
mkdir -p "./usr/share/man/man1/"
97-
gzip --stdout ../../doc/e9patch.1 > ./usr/share/man/man1/e9patch.1.gz
98-
gzip --stdout ../../doc/e9tool.1 > ./usr/share/man/man1/e9tool.1.gz
99-
gzip --stdout ../../doc/e9compile.1 > ./usr/share/man/man1/e9compile.1.gz
46+
cd install/data
10047
tar cz --owner root --group root -f ../data.tar.gz .
10148
md5sum `find ../data/ -type f -printf "%P "` > ../control/md5sums
10249

src/e9tool/e9dwarf.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
#include "e9misc.h"
2929
#include "e9tool.h"
3030

31+
#ifdef SYSTEM_LIBDW
32+
#include <elfutils/libdw.h>
33+
#else
3134
#include "libdw.h"
35+
#endif
3236

3337
using namespace e9tool;
3438

0 commit comments

Comments
 (0)