x86/mm: avoid building multiple .o from a single .c file
authorAnthony PERARD <anthony.perard@citrix.com>
Tue, 12 Oct 2021 09:48:46 +0000 (11:48 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 12 Oct 2021 09:48:46 +0000 (11:48 +0200)
This replace the use of a single .c file use for multiple .o file by
creating multiple .c file including the first one.

There's quite a few issues with trying to build more than one object
file from a single source file: there's is a duplication of the make
rules to generate those targets; there is an additional ".file" symbol
added in order to differentiate between the object files; and the
tools/symbols have an heuristic to try to pick up the right ".file".

This patch adds new .c source file which avoid the need to add a
second ".file" symbol and thus avoid the need to deal with those
issues.

Also remove __OBJECT_FILE__ from $(CC) command line as it isn't used
anywhere anymore. And remove the macro "build-intermediate" since the
generic rules for single targets can be used.

And rename the objects in mm/hap/ to remove the extra "level".

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
18 files changed:
xen/Makefile
xen/Rules.mk
xen/arch/x86/mm/Makefile
xen/arch/x86/mm/guest_walk.c
xen/arch/x86/mm/guest_walk_2.c [new file with mode: 0644]
xen/arch/x86/mm/guest_walk_3.c [new file with mode: 0644]
xen/arch/x86/mm/guest_walk_4.c [new file with mode: 0644]
xen/arch/x86/mm/hap/Makefile
xen/arch/x86/mm/hap/guest_walk.c
xen/arch/x86/mm/hap/guest_walk_2.c [new file with mode: 0644]
xen/arch/x86/mm/hap/guest_walk_3.c [new file with mode: 0644]
xen/arch/x86/mm/hap/guest_walk_4.c [new file with mode: 0644]
xen/arch/x86/mm/shadow/Makefile
xen/arch/x86/mm/shadow/guest_2.c [new file with mode: 0644]
xen/arch/x86/mm/shadow/guest_3.c [new file with mode: 0644]
xen/arch/x86/mm/shadow/guest_4.c [new file with mode: 0644]
xen/arch/x86/mm/shadow/multi.c
xen/tools/symbols.c

index 7c2ffce0fc7776baaef9a10cd2d4c2e397c70d4b..5d011016621b3e86ca60ea2721b2e4bd7ff4565f 100644 (file)
@@ -518,17 +518,6 @@ _MAP:
 %/: FORCE
        $(MAKE) -f $(BASEDIR)/Rules.mk -C $* built_in.o built_in_bin.o
 
-build-intermediate = $(eval $(call build-intermediate-closure,$(1)))
-define build-intermediate-closure
-$(1): FORCE
-       $(MAKE) -f $(BASEDIR)/Rules.mk -C $$(@D) $$(@F)
-endef
-
-$(foreach base,arch/x86/mm/guest_walk_% \
-               arch/x86/mm/hap/guest_walk_%level \
-               arch/x86/mm/shadow/guest_%, \
-    $(foreach ext,o i s,$(call build-intermediate,$(base).$(ext))))
-
 .PHONY: cloc
 cloc:
        $(eval tmpfile := $(shell mktemp))
index 8b8f9d347fb858884a0339911fb48f41f172f7b5..5e0699e58b2b02231bea994acde854944ac14a22 100644 (file)
@@ -122,7 +122,7 @@ cpp_flags = $(filter-out -Wa$(comma)% -flto,$(1))
 # Calculation of flags, first the generic flags, then the arch specific flags,
 # and last the flags modified for a target or a directory.
 
-c_flags = -MMD -MP -MF $(@D)/.$(@F).d $(XEN_CFLAGS) '-D__OBJECT_FILE__="$@"'
+c_flags = -MMD -MP -MF $(@D)/.$(@F).d $(XEN_CFLAGS)
 a_flags = -MMD -MP -MF $(@D)/.$(@F).d $(XEN_AFLAGS)
 
 include $(BASEDIR)/arch/$(TARGET_ARCH)/Rules.mk
index 2818c066f76a33c3dc108dbf97b8d6363f5d5fa4..6b7882d992bb7d918ced600df972a75c49e08b5f 100644 (file)
@@ -10,12 +10,3 @@ obj-$(CONFIG_MEM_SHARING) += mem_sharing.o
 obj-y += p2m.o
 obj-$(CONFIG_HVM) += p2m-ept.o p2m-pod.o p2m-pt.o
 obj-y += paging.o
-
-guest_walk_%.o: guest_walk.c Makefile
-       $(CC) $(c_flags) -DGUEST_PAGING_LEVELS=$* -c $< -o $@
-
-guest_walk_%.i: guest_walk.c Makefile
-       $(CPP) $(call cpp_flags,$(c_flags)) -DGUEST_PAGING_LEVELS=$* -c $< -o $@
-
-guest_walk_%.s: guest_walk.c Makefile
-       $(CC) $(filter-out -Wa$(comma)%,$(c_flags)) -DGUEST_PAGING_LEVELS=$* -S $< -o $@
index 30d83cf1e0e6ab4e2c47a8a444e03adb79856a9b..b9f607272c3950d12357bc31d4217709bae8f1ff 100644 (file)
@@ -21,9 +21,6 @@
  * along with this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* Allow uniquely identifying static symbols in the 3 generated objects. */
-asm(".file \"" __OBJECT_FILE__ "\"");
-
 #include <xen/types.h>
 #include <xen/mm.h>
 #include <xen/paging.h>
diff --git a/xen/arch/x86/mm/guest_walk_2.c b/xen/arch/x86/mm/guest_walk_2.c
new file mode 100644 (file)
index 0000000..defcd59
--- /dev/null
@@ -0,0 +1,2 @@
+#define GUEST_PAGING_LEVELS 2
+#include "guest_walk.c"
diff --git a/xen/arch/x86/mm/guest_walk_3.c b/xen/arch/x86/mm/guest_walk_3.c
new file mode 100644 (file)
index 0000000..1c9eca3
--- /dev/null
@@ -0,0 +1,2 @@
+#define GUEST_PAGING_LEVELS 3
+#include "guest_walk.c"
diff --git a/xen/arch/x86/mm/guest_walk_4.c b/xen/arch/x86/mm/guest_walk_4.c
new file mode 100644 (file)
index 0000000..aa39003
--- /dev/null
@@ -0,0 +1,2 @@
+#define GUEST_PAGING_LEVELS 4
+#include "guest_walk.c"
index c6d296b51720617854bdd25b8056fe1ad680f073..8ef54b1faa500385366e4a13bc85dd0a116553ba 100644 (file)
@@ -1,15 +1,6 @@
 obj-y += hap.o
-obj-y += guest_walk_2level.o
-obj-y += guest_walk_3level.o
-obj-y += guest_walk_4level.o
+obj-y += guest_walk_2.o
+obj-y += guest_walk_3.o
+obj-y += guest_walk_4.o
 obj-y += nested_hap.o
 obj-y += nested_ept.o
-
-guest_walk_%level.o: guest_walk.c Makefile
-       $(CC) $(c_flags) -DGUEST_PAGING_LEVELS=$* -c $< -o $@
-
-guest_walk_%level.i: guest_walk.c Makefile
-       $(CPP) $(call cpp_flags,$(c_flags)) -DGUEST_PAGING_LEVELS=$* -c $< -o $@
-
-guest_walk_%level.s: guest_walk.c Makefile
-       $(CC) $(filter-out -Wa$(comma)%,$(c_flags)) -DGUEST_PAGING_LEVELS=$* -S $< -o $@
index f59ebc84a29040ceca31ac08df45ab5306c6fdae..832a8058471ee8c5f6b36d322281ac458e7cf50c 100644 (file)
@@ -18,9 +18,6 @@
  * this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* Allow uniquely identifying static symbols in the 3 generated objects. */
-asm(".file \"" __OBJECT_FILE__ "\"");
-
 #include <xen/domain_page.h>
 #include <xen/paging.h>
 #include <xen/sched.h>
diff --git a/xen/arch/x86/mm/hap/guest_walk_2.c b/xen/arch/x86/mm/hap/guest_walk_2.c
new file mode 100644 (file)
index 0000000..defcd59
--- /dev/null
@@ -0,0 +1,2 @@
+#define GUEST_PAGING_LEVELS 2
+#include "guest_walk.c"
diff --git a/xen/arch/x86/mm/hap/guest_walk_3.c b/xen/arch/x86/mm/hap/guest_walk_3.c
new file mode 100644 (file)
index 0000000..1c9eca3
--- /dev/null
@@ -0,0 +1,2 @@
+#define GUEST_PAGING_LEVELS 3
+#include "guest_walk.c"
diff --git a/xen/arch/x86/mm/hap/guest_walk_4.c b/xen/arch/x86/mm/hap/guest_walk_4.c
new file mode 100644 (file)
index 0000000..aa39003
--- /dev/null
@@ -0,0 +1,2 @@
+#define GUEST_PAGING_LEVELS 4
+#include "guest_walk.c"
index fd64b4dda9257a62cfcbc12f6ffa23c0f4af75c0..b4a1620b69206ab9dc127ccc1a220c57ee7ea017 100644 (file)
@@ -5,12 +5,3 @@ obj-$(CONFIG_PV) += pv.o guest_4.o
 else
 obj-y += none.o
 endif
-
-guest_%.o: multi.c Makefile
-       $(CC) $(c_flags) -DGUEST_PAGING_LEVELS=$* -c $< -o $@
-
-guest_%.i: multi.c Makefile
-       $(CPP) $(call cpp_flags,$(c_flags)) -DGUEST_PAGING_LEVELS=$* -c $< -o $@
-
-guest_%.s: multi.c Makefile
-       $(CC) $(filter-out -Wa$(comma)%,$(c_flags)) -DGUEST_PAGING_LEVELS=$* -S $< -o $@
diff --git a/xen/arch/x86/mm/shadow/guest_2.c b/xen/arch/x86/mm/shadow/guest_2.c
new file mode 100644 (file)
index 0000000..288b229
--- /dev/null
@@ -0,0 +1,2 @@
+#define GUEST_PAGING_LEVELS 2
+#include "multi.c"
diff --git a/xen/arch/x86/mm/shadow/guest_3.c b/xen/arch/x86/mm/shadow/guest_3.c
new file mode 100644 (file)
index 0000000..04e17b0
--- /dev/null
@@ -0,0 +1,2 @@
+#define GUEST_PAGING_LEVELS 3
+#include "multi.c"
diff --git a/xen/arch/x86/mm/shadow/guest_4.c b/xen/arch/x86/mm/shadow/guest_4.c
new file mode 100644 (file)
index 0000000..c0c5d3c
--- /dev/null
@@ -0,0 +1,2 @@
+#define GUEST_PAGING_LEVELS 4
+#include "multi.c"
index 15265fc81dcaf8f20620a43f371414b9866c2c94..a2fa7b87d878fe947c41bf37b9a71b366a5af7b3 100644 (file)
@@ -20,9 +20,6 @@
  * along with this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* Allow uniquely identifying static symbols in the 3 generated objects. */
-asm(".file \"" __OBJECT_FILE__ "\"");
-
 #include <xen/types.h>
 #include <xen/mm.h>
 #include <xen/trace.h>
index 0b124526165dcae2efbd232816f3398abd82d7c4..710e9785d348ca3f67ad4588f26b56afecefd3f8 100644 (file)
@@ -84,7 +84,6 @@ static int read_symbol(FILE *in, struct sym_entry *s)
 {
        char str[500], type[20] = "";
        char *sym, stype;
-       static enum { symbol, single_source, multi_source } last;
        static char *filename;
        int rc = -1;
 
@@ -118,24 +117,11 @@ static int read_symbol(FILE *in, struct sym_entry *s)
              */
             input_format == fmt_sysv && !*type && stype == '?' && sym &&
             sym[1] && strchr("cSsoh", sym[1]) && !sym[2])) {
-               /*
-                * gas prior to binutils commit fbdf9406b0 (expected to appear
-                * in 2.27) outputs symbol table entries resulting from .file
-                * in reverse order. If we get two consecutive file symbols,
-                * prefer the first one if that names an object file or has a
-                * directory component (to cover multiply compiled files).
-                */
-               bool multi = strchr(str, '/') || (sym && sym[1] == 'o');
-
-               if (multi || last != multi_source) {
-                       free(filename);
-                       filename = *str ? strdup(str) : NULL;
-               }
-               last = multi ? multi_source : single_source;
+               free(filename);
+               filename = *str ? strdup(str) : NULL;
                goto skip_tail;
        }
 
-       last = symbol;
        rc = -1;
 
        sym = str;