Skip to contentSkip to conversation

rules.mak: Force CFLAGS for all objects in DSO

PATCH In review Fam Zheng 2 participants 3 messages May 7, 2015 – May 12, 2015

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH v2 1/1 rules.mak: Force CFLAGS for all objects in DSO

Because of the trick of process-archive-undefs, all .mo objects, even with --enable-modules, are dependencies of executables.

This breaks CFLAGS propogation because the compiling of module object will happen too early before building for DSO.

With GCC 5, the linking would fail because .o doesn't have -fPIC. Also, BUILD_DSO will be missed. (module-common.o will have it, so the stamp symbol was still liked in .so).

Fix the problem by forcing the CFLAGS on individual .o-cflags during unnest-vars.

---

v2: Simplify as Paolo suggested, while keeping the CFLAGS of module-common.o

---
 rules.mak | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
rules.mak +3 -1
index 3a05627..aec27f8 100644
@@ -102,7 +102,8 @@ endif
 %.o: %.dtrace
 	$(call quiet-command,dtrace -o $@ -G -s $<, "  GEN   $(TARGET_DIR)$@")
 
-%$(DSOSUF): CFLAGS += -fPIC -DBUILD_DSO
+DSO_OBJ_CFLAGS := -fPIC -DBUILD_DSO
+module-common.o: CFLAGS += $(DSO_OBJ_CFLAGS)
 %$(DSOSUF): LDFLAGS += $(LDFLAGS_SHARED)
 %$(DSOSUF): %.mo
 	$(call LINK,$^)
@@ -351,6 +352,7 @@ define unnest-vars
         # For non-module build, add -m to -y
         $(if $(CONFIG_MODULES),
              $(foreach o,$($v),
+                   $(eval $($o-objs): CFLAGS += $(DSO_OBJ_CFLAGS))
                    $(eval $o: $($o-objs)))
              $(eval $(patsubst %-m,%-y,$v) += $($v))
              $(eval modules: $($v:%.mo=%$(DSOSUF))),
Signature · 1 line
2.1.0
#1 lore raw

Am 07.05.2015 um 08:55 schrieb Fam Zheng:

Quoted 9 lines

Because of the trick of process-archive-undefs, all .mo objects, even with --enable-modules, are dependencies of executables.

This breaks CFLAGS propogation because the compiling of module object will happen too early before building for DSO.

With GCC 5, the linking would fail because .o doesn't have -fPIC. Also, BUILD_DSO will be missed. (module-common.o will have it, so the stamp symbol was still liked in .so).

Did you mean "linked"?

Cheers,
Andreas

Quoted 38 lines

Fix the problem by forcing the CFLAGS on individual .o-cflags during unnest-vars.

---

v2: Simplify as Paolo suggested, while keeping the CFLAGS of module-common.o

---
 rules.mak | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
rules.mak +3 -1
index 3a05627..aec27f8 100644
@@ -102,7 +102,8 @@ endif
 %.o: %.dtrace
 	$(call quiet-command,dtrace -o $@ -G -s $<, "  GEN   $(TARGET_DIR)$@")
 
-%$(DSOSUF): CFLAGS += -fPIC -DBUILD_DSO
+DSO_OBJ_CFLAGS := -fPIC -DBUILD_DSO
+module-common.o: CFLAGS += $(DSO_OBJ_CFLAGS)
 %$(DSOSUF): LDFLAGS += $(LDFLAGS_SHARED)
 %$(DSOSUF): %.mo
 	$(call LINK,$^)
@@ -351,6 +352,7 @@ define unnest-vars
         # For non-module build, add -m to -y
         $(if $(CONFIG_MODULES),
              $(foreach o,$($v),
+                   $(eval $($o-objs): CFLAGS += $(DSO_OBJ_CFLAGS))
                    $(eval $o: $($o-objs)))
              $(eval $(patsubst %-m,%-y,$v) += $($v))
              $(eval modules: $($v:%.mo=%$(DSOSUF))),
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)
author
#2 lore raw
Quoted 4 lines · Andreas Färber

Am 07.05.2015 um 08:55 schrieb Fam Zheng:

Quoted 3 lines

Because of the trick of process-archive-undefs, all .mo objects, even with --enable-modules, are dependencies of executables.

Quoted 8 lines
Quoted 6 lines

This breaks CFLAGS propogation because the compiling of module object will happen too early before building for DSO.

With GCC 5, the linking would fail because .o doesn't have -fPIC. Also, BUILD_DSO will be missed. (module-common.o will have it, so the stamp symbol was still liked in .so).

Did you mean "linked"?

Yes but it's too late, the commit is already applied to qemu.git :(

Fam

Quoted 49 lines

Cheers,
Andreas

Quoted 38 lines

Fix the problem by forcing the CFLAGS on individual .o-cflags during unnest-vars.

---

v2: Simplify as Paolo suggested, while keeping the CFLAGS of module-common.o

---
 rules.mak | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
rules.mak +3 -1
index 3a05627..aec27f8 100644
@@ -102,7 +102,8 @@ endif
 %.o: %.dtrace
 	$(call quiet-command,dtrace -o $@ -G -s $<, "  GEN   $(TARGET_DIR)$@")
 
-%$(DSOSUF): CFLAGS += -fPIC -DBUILD_DSO
+DSO_OBJ_CFLAGS := -fPIC -DBUILD_DSO
+module-common.o: CFLAGS += $(DSO_OBJ_CFLAGS)
 %$(DSOSUF): LDFLAGS += $(LDFLAGS_SHARED)
 %$(DSOSUF): %.mo
 	$(call LINK,$^)
@@ -351,6 +352,7 @@ define unnest-vars
         # For non-module build, add -m to -y
         $(if $(CONFIG_MODULES),
              $(foreach o,$($v),
+                   $(eval $($o-objs): CFLAGS += $(DSO_OBJ_CFLAGS))
                    $(eval $o: $($o-objs)))
              $(eval $(patsubst %-m,%-y,$v) += $($v))
              $(eval modules: $($v:%.mo=%$(DSOSUF))),
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)