commit: 1f3572f01249e929feb26309fed5c2ce7d932a86 Author: Mike Frysinger <vapier <AT> chromium <DOT> org> AuthorDate: Fri Apr 16 17:00:01 2021 +0000 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> CommitDate: Fri Apr 16 17:00:01 2021 +0000 URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=1f3572f0
build: support debugging/testing object internals Add a hack so we can build individual objects as standalone programs. This way we can more easily poke internal static funcs to aid in the overall debugging/development process. Bug: https://bugs.gentoo.org/739014 Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org> .gitignore | 3 +++ Makefile | 20 +++++++++++++++----- paxldso.c | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 6e0a530..33f051f 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,9 @@ stamp-h1 /dumpelf /lddtree +/paxelf +/paxldso +/paxmacho /pspax /scanelf /scanmacho diff --git a/Makefile b/Makefile index c906311..8a54faf 100644 --- a/Makefile +++ b/Makefile @@ -67,19 +67,26 @@ endif override CPPFLAGS += -DVCSID='"$(VCSID)"' #################################################################### -ELF_TARGETS = scanelf dumpelf $(shell echo | $(CC) -dM -E - | grep -q __svr4__ || echo pspax) +ELF_TARGETS = scanelf dumpelf $(shell $(CC) -dM -E - </dev/null | grep -q __svr4__ || echo pspax) ELF_OBJS = paxelf.o paxldso.o MACH_TARGETS = scanmacho MACH_OBJS = paxmacho.o COMMON_OBJS = paxinc.o security.o xfuncs.o TARGETS = $(ELF_TARGETS) $(MACH_TARGETS) +TARGETS_OBJS = $(TARGETS:%=%.o) SCRIPTS_SH = lddtree symtree SCRIPTS_PY = lddtree -OBJS = $(ELF_OBJS) $(MACH_OBJS) $(COMMON_OBJS) $(TARGETS:%=%.o) +_OBJS = $(ELF_OBJS) $(MACH_OBJS) $(COMMON_OBJS) +OBJS = $(_OBJS) $(TARGETS_OBJS) +# Not all objects support this hack. Otherwise we'd use $(_OBJS:%.o=%) +OBJS_TARGETS = paxldso MPAGES = $(TARGETS:%=man/%.1) SOURCES = $(OBJS:%.o=%.c) -all: $(OBJS) $(TARGETS) +all: $(TARGETS) + @: + +all-dev: all $(OBJS_TARGETS) @: DEBUG_FLAGS = \ @@ -88,7 +95,7 @@ DEBUG_FLAGS = \ -fsanitize=leak \ -fsanitize=undefined debug: clean - $(MAKE) CFLAGS="$(CFLAGS) -g3 -ggdb $(call check_compiler_many,$(DEBUG_FLAGS))" all + $(MAKE) CFLAGS="$(CFLAGS) -g3 -ggdb $(call check_compiler_many,$(DEBUG_FLAGS))" all-dev @-chpax -permsx $(ELF_TARGETS) @-paxctl -permsx $(ELF_TARGETS) @@ -120,6 +127,9 @@ $(ELF_TARGETS): %: $(ELF_OBJS) $(COMMON_OBJS) %.o $(MACH_TARGETS): %: $(MACH_OBJS) $(COMMON_OBJS) %.o $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS) $(LIBS-$@) +$(OBJS_TARGETS): %: $(_OBJS) %.c + $(CC) $(CFLAGS) $(CPPFLAGS) -DMAIN $(LDFLAGS) $(filter-out [email protected],$^) -o $@ $(LIBS) $(LIBS-$@) + %.so: %.c $(CC) -shared -fPIC -o $@ $< @@ -127,7 +137,7 @@ depend: $(CC) $(CFLAGS) -MM $(SOURCES) > .depend clean: - -rm -f $(OBJS) $(TARGETS) + -rm -f $(OBJS) $(TARGETS) $(OBJS_TARGETS) distclean: clean -rm -f *~ core *.o diff --git a/paxldso.c b/paxldso.c index 2d8ddea..d89210d 100644 --- a/paxldso.c +++ b/paxldso.c @@ -371,3 +371,21 @@ void paxldso_cleanup(void) #endif const char * ldcache_path = "/etc/ld.so.cache"; + +#ifdef MAIN + +const char argv0[] = "paxldso"; + +int main(int argc, char *argv[]) +{ + elfobj *elf = readelf(argv[0]); + for (int i = 1; i < argc; ++i) { + const char *search = argv[i]; + const char *lib = ldso_cache_lookup_lib(elf, search); + printf("%s -> %s\n", search, lib); + } + unreadelf(elf); + paxldso_cleanup(); +} + +#endif
