From d4c6267e4f8b28df6c98e1c6c5cb90021ce3665d Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Tue, 24 Mar 2020 23:21:25 -0700 Subject: Always build with -fPIC The dladdr(3) explains that dladdr often doesn't do what you expect because the function pointer will point to the PLT entry in the original object and not the actual function itself. --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 22ee038..c551882 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. +CFLAGS += -fPIC LDLIBS = -ldl LDFLAGS = -Wl,--build-id=sha1 GREP_SHA1 = egrep -o '\b[0-9a-f]{40}\b' @@ -35,7 +36,7 @@ dlopen-build-id: dlopen-test.o $(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) shared-build-id.o: build-id.c - $(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -c $^ -o $@ + $(CC) $(CPPFLAGS) $(CFLAGS) -c $^ -o $@ libbuild-id.so: shared-build-id.o $(CC) $(LDFLAGS) -shared $^ -o $@ $(LDLIBS) -- cgit v1.2.3