[lttng-dev] [PATCH lttng-ust] Fix: build example SO when PIE is enabled

Michael Jeanson mjeanson at efficios.com
Wed Oct 25 18:28:04 UTC 2017


In the example Makefiles, when building shared object libraires, make sure
we set the custom linker options after the CFLAGS/LDFLAGS so that it
overrides them. This is useful when the build system set some hardening
features like PIE in the CFLAGS.

Signed-off-by: Michael Jeanson <mjeanson at efficios.com>
---
 doc/examples/clock-override/Makefile  | 4 ++--
 doc/examples/demo/Makefile            | 8 ++++----
 doc/examples/getcpu-override/Makefile | 4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/doc/examples/clock-override/Makefile b/doc/examples/clock-override/Makefile
index 5433427..22e5dff 100644
--- a/doc/examples/clock-override/Makefile
+++ b/doc/examples/clock-override/Makefile
@@ -26,8 +26,8 @@ lttng-ust-clock-override-example.o: lttng-ust-clock-override-example.c
 		$(CFLAGS) -fpic -c -o $@ $<
 
 lttng-ust-clock-override-example.so: lttng-ust-clock-override-example.o
-	$(CC) -shared -Wl,--no-as-needed -o $@ $(LDFLAGS) $(AM_CFLAGS) \
-		$(AM_LDFLAGS) $(CFLAGS) lttng-ust-clock-override-example.o
+	$(CC) -Wl,--no-as-needed -o $@ $(LDFLAGS) $(AM_CFLAGS) \
+		$(AM_LDFLAGS) $(CFLAGS) -shared -fpic lttng-ust-clock-override-example.o
 
 .PHONY: clean
 clean:
diff --git a/doc/examples/demo/Makefile b/doc/examples/demo/Makefile
index 6272a2b..bb7fc17 100644
--- a/doc/examples/demo/Makefile
+++ b/doc/examples/demo/Makefile
@@ -29,16 +29,16 @@ tp2.o: tp2.c ust_tests_demo2.h
 		$(CFLAGS) -fpic -c -o $@ $<
 
 lttng-ust-provider-ust-tests-demo.so: tp.o tp2.o
-	$(CC) -shared -Wl,--no-as-needed -o $@ $(LDFLAGS) $(AM_CFLAGS) \
-		$(AM_LDFLAGS) $(CFLAGS) -llttng-ust tp.o tp2.o
+	$(CC) -Wl,--no-as-needed -o $@ $(LDFLAGS) $(AM_CFLAGS) \
+		$(AM_LDFLAGS) $(CFLAGS) -shared -fpic tp.o tp2.o $(LIBS) -llttng-ust
 
 tp3.o: tp3.c ust_tests_demo3.h
 	$(CC) $(CPPFLAGS) $(LOCAL_CPPFLAGS) $(AM_CFLAGS) $(AM_CPPFLAGS) \
 		$(CFLAGS) -fpic -c -o $@ $<
 
 lttng-ust-provider-ust-tests-demo3.so: tp3.o
-	$(CC) -shared -Wl,--no-as-needed -o $@ $(LDFLAGS) $(AM_CFLAGS) \
-		$(AM_LDFLAGS) $(CFLAGS) -llttng-ust tp3.o
+	$(CC) -Wl,--no-as-needed -o $@ $(LDFLAGS) $(AM_CFLAGS) \
+		$(AM_LDFLAGS) $(CFLAGS) -shared -fpic tp3.o $(LIBS) -llttng-ust
 
 demo.o: demo.c
 	$(CC) $(CPPFLAGS) $(LOCAL_CPPFLAGS) $(AM_CFLAGS) $(AM_CPPFLAGS) \
diff --git a/doc/examples/getcpu-override/Makefile b/doc/examples/getcpu-override/Makefile
index de295c6..e1e4892 100644
--- a/doc/examples/getcpu-override/Makefile
+++ b/doc/examples/getcpu-override/Makefile
@@ -26,8 +26,8 @@ lttng-ust-getcpu-override-example.o: lttng-ust-getcpu-override-example.c
 		$(CFLAGS) -fpic -c -o $@ $<
 
 lttng-ust-getcpu-override-example.so: lttng-ust-getcpu-override-example.o
-	$(CC) -shared -Wl,--no-as-needed -o $@ $(LDFLAGS) $(AM_CFLAGS) \
-		$(AM_LDFLAGS) $(CFLAGS) lttng-ust-getcpu-override-example.o
+	$(CC) -Wl,--no-as-needed -o $@ $(LDFLAGS) $(AM_CFLAGS) \
+		$(AM_LDFLAGS) $(CFLAGS) -shared -fpic lttng-ust-getcpu-override-example.o
 
 .PHONY: clean
 clean:
-- 
2.7.4



More information about the lttng-dev mailing list