Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/pax-utils:master commit in: /
Date: Fri, 16 Apr 2021 19:03:39
Message-Id: 1618592401.1f3572f01249e929feb26309fed5c2ce7d932a86.vapier@gentoo
1 commit: 1f3572f01249e929feb26309fed5c2ce7d932a86
2 Author: Mike Frysinger <vapier <AT> chromium <DOT> org>
3 AuthorDate: Fri Apr 16 17:00:01 2021 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Fri Apr 16 17:00:01 2021 +0000
6 URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=1f3572f0
7
8 build: support debugging/testing object internals
9
10 Add a hack so we can build individual objects as standalone programs.
11 This way we can more easily poke internal static funcs to aid in the
12 overall debugging/development process.
13
14 Bug: https://bugs.gentoo.org/739014
15 Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>
16
17 .gitignore | 3 +++
18 Makefile | 20 +++++++++++++++-----
19 paxldso.c | 18 ++++++++++++++++++
20 3 files changed, 36 insertions(+), 5 deletions(-)
21
22 diff --git a/.gitignore b/.gitignore
23 index 6e0a530..33f051f 100644
24 --- a/.gitignore
25 +++ b/.gitignore
26 @@ -36,6 +36,9 @@ stamp-h1
27
28 /dumpelf
29 /lddtree
30 +/paxelf
31 +/paxldso
32 +/paxmacho
33 /pspax
34 /scanelf
35 /scanmacho
36
37 diff --git a/Makefile b/Makefile
38 index c906311..8a54faf 100644
39 --- a/Makefile
40 +++ b/Makefile
41 @@ -67,19 +67,26 @@ endif
42 override CPPFLAGS += -DVCSID='"$(VCSID)"'
43
44 ####################################################################
45 -ELF_TARGETS = scanelf dumpelf $(shell echo | $(CC) -dM -E - | grep -q __svr4__ || echo pspax)
46 +ELF_TARGETS = scanelf dumpelf $(shell $(CC) -dM -E - </dev/null | grep -q __svr4__ || echo pspax)
47 ELF_OBJS = paxelf.o paxldso.o
48 MACH_TARGETS = scanmacho
49 MACH_OBJS = paxmacho.o
50 COMMON_OBJS = paxinc.o security.o xfuncs.o
51 TARGETS = $(ELF_TARGETS) $(MACH_TARGETS)
52 +TARGETS_OBJS = $(TARGETS:%=%.o)
53 SCRIPTS_SH = lddtree symtree
54 SCRIPTS_PY = lddtree
55 -OBJS = $(ELF_OBJS) $(MACH_OBJS) $(COMMON_OBJS) $(TARGETS:%=%.o)
56 +_OBJS = $(ELF_OBJS) $(MACH_OBJS) $(COMMON_OBJS)
57 +OBJS = $(_OBJS) $(TARGETS_OBJS)
58 +# Not all objects support this hack. Otherwise we'd use $(_OBJS:%.o=%)
59 +OBJS_TARGETS = paxldso
60 MPAGES = $(TARGETS:%=man/%.1)
61 SOURCES = $(OBJS:%.o=%.c)
62
63 -all: $(OBJS) $(TARGETS)
64 +all: $(TARGETS)
65 + @:
66 +
67 +all-dev: all $(OBJS_TARGETS)
68 @:
69
70 DEBUG_FLAGS = \
71 @@ -88,7 +95,7 @@ DEBUG_FLAGS = \
72 -fsanitize=leak \
73 -fsanitize=undefined
74 debug: clean
75 - $(MAKE) CFLAGS="$(CFLAGS) -g3 -ggdb $(call check_compiler_many,$(DEBUG_FLAGS))" all
76 + $(MAKE) CFLAGS="$(CFLAGS) -g3 -ggdb $(call check_compiler_many,$(DEBUG_FLAGS))" all-dev
77 @-chpax -permsx $(ELF_TARGETS)
78 @-paxctl -permsx $(ELF_TARGETS)
79
80 @@ -120,6 +127,9 @@ $(ELF_TARGETS): %: $(ELF_OBJS) $(COMMON_OBJS) %.o
81 $(MACH_TARGETS): %: $(MACH_OBJS) $(COMMON_OBJS) %.o
82 $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS) $(LIBS-$@)
83
84 +$(OBJS_TARGETS): %: $(_OBJS) %.c
85 + $(CC) $(CFLAGS) $(CPPFLAGS) -DMAIN $(LDFLAGS) $(filter-out $@.o,$^) -o $@ $(LIBS) $(LIBS-$@)
86 +
87 %.so: %.c
88 $(CC) -shared -fPIC -o $@ $<
89
90 @@ -127,7 +137,7 @@ depend:
91 $(CC) $(CFLAGS) -MM $(SOURCES) > .depend
92
93 clean:
94 - -rm -f $(OBJS) $(TARGETS)
95 + -rm -f $(OBJS) $(TARGETS) $(OBJS_TARGETS)
96
97 distclean: clean
98 -rm -f *~ core *.o
99
100 diff --git a/paxldso.c b/paxldso.c
101 index 2d8ddea..d89210d 100644
102 --- a/paxldso.c
103 +++ b/paxldso.c
104 @@ -371,3 +371,21 @@ void paxldso_cleanup(void)
105 #endif
106
107 const char * ldcache_path = "/etc/ld.so.cache";
108 +
109 +#ifdef MAIN
110 +
111 +const char argv0[] = "paxldso";
112 +
113 +int main(int argc, char *argv[])
114 +{
115 + elfobj *elf = readelf(argv[0]);
116 + for (int i = 1; i < argc; ++i) {
117 + const char *search = argv[i];
118 + const char *lib = ldso_cache_lookup_lib(elf, search);
119 + printf("%s -> %s\n", search, lib);
120 + }
121 + unreadelf(elf);
122 + paxldso_cleanup();
123 +}
124 +
125 +#endif