All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony PERARD <anthony.perard@citrix.com>
To: <xen-devel@lists.xenproject.org>
Cc: "Anthony PERARD" <anthony.perard@citrix.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"George Dunlap" <george.dunlap@citrix.com>,
	"Ian Jackson" <iwj@xenproject.org>,
	"Jan Beulich" <jbeulich@suse.com>,
	"Julien Grall" <julien@xen.org>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Wei Liu" <wl@xen.org>, "Roger Pau Monné" <roger.pau@citrix.com>,
	"Tim Deegan" <tim@xen.org>
Subject: [XEN PATCH v6 06/31] x86/mm: avoid building multiple .o from a single .c file
Date: Thu, 1 Jul 2021 15:09:46 +0100	[thread overview]
Message-ID: <20210701141011.785641-7-anthony.perard@citrix.com> (raw)
In-Reply-To: <20210701141011.785641-1-anthony.perard@citrix.com>

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.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---

Notes:
    v6:
    - new patch
      to replace both from v5:
        xen,symbols: rework file symbols selection
        build: use if_changed to build mm/*/guest_%.o
    
    The changes in the patch for symbols.c was too complicated to explain,
    and I probably didn't realize one important fact about the tool: it deal
    with all *.o been concatenated to each other, without a way to figure
    out which symbol belong to which original file, and certainly no way to
    figure out if there's more than one ".file" symbol to choose from beside
    some fragile heuristic.

 xen/Makefile                            | 11 -----------
 xen/Rules.mk                            |  2 +-
 xen/arch/x86/mm/Makefile                |  9 ---------
 xen/arch/x86/mm/guest_walk.c            |  3 ---
 xen/arch/x86/mm/guest_walk_2.c          |  2 ++
 xen/arch/x86/mm/guest_walk_3.c          |  2 ++
 xen/arch/x86/mm/guest_walk_4.c          |  2 ++
 xen/arch/x86/mm/hap/Makefile            |  9 ---------
 xen/arch/x86/mm/hap/guest_walk.c        |  3 ---
 xen/arch/x86/mm/hap/guest_walk_2level.c |  2 ++
 xen/arch/x86/mm/hap/guest_walk_3level.c |  2 ++
 xen/arch/x86/mm/hap/guest_walk_4level.c |  2 ++
 xen/arch/x86/mm/shadow/Makefile         |  9 ---------
 xen/arch/x86/mm/shadow/guest_2.c        |  2 ++
 xen/arch/x86/mm/shadow/guest_3.c        |  2 ++
 xen/arch/x86/mm/shadow/guest_4.c        |  2 ++
 xen/arch/x86/mm/shadow/multi.c          |  3 ---
 xen/tools/symbols.c                     | 18 ++----------------
 18 files changed, 21 insertions(+), 64 deletions(-)
 create mode 100644 xen/arch/x86/mm/guest_walk_2.c
 create mode 100644 xen/arch/x86/mm/guest_walk_3.c
 create mode 100644 xen/arch/x86/mm/guest_walk_4.c
 create mode 100644 xen/arch/x86/mm/hap/guest_walk_2level.c
 create mode 100644 xen/arch/x86/mm/hap/guest_walk_3level.c
 create mode 100644 xen/arch/x86/mm/hap/guest_walk_4level.c
 create mode 100644 xen/arch/x86/mm/shadow/guest_2.c
 create mode 100644 xen/arch/x86/mm/shadow/guest_3.c
 create mode 100644 xen/arch/x86/mm/shadow/guest_4.c

diff --git a/xen/Makefile b/xen/Makefile
index 89879fad4cb2..360b4a1d1867 100644
--- a/xen/Makefile
+++ b/xen/Makefile
@@ -476,17 +476,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))
diff --git a/xen/Rules.mk b/xen/Rules.mk
index f05b2d3f0399..ede408efc515 100644
--- a/xen/Rules.mk
+++ b/xen/Rules.mk
@@ -139,7 +139,7 @@ cpp_flags = $(filter-out -Wa$(comma)%,$(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
diff --git a/xen/arch/x86/mm/Makefile b/xen/arch/x86/mm/Makefile
index 2818c066f76a..6b7882d992bb 100644
--- a/xen/arch/x86/mm/Makefile
+++ b/xen/arch/x86/mm/Makefile
@@ -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 $@
diff --git a/xen/arch/x86/mm/guest_walk.c b/xen/arch/x86/mm/guest_walk.c
index 30d83cf1e0e6..b9f607272c39 100644
--- a/xen/arch/x86/mm/guest_walk.c
+++ b/xen/arch/x86/mm/guest_walk.c
@@ -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
index 000000000000..defcd59bc260
--- /dev/null
+++ b/xen/arch/x86/mm/guest_walk_2.c
@@ -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
index 000000000000..1c9eca37741e
--- /dev/null
+++ b/xen/arch/x86/mm/guest_walk_3.c
@@ -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
index 000000000000..aa3900338a2d
--- /dev/null
+++ b/xen/arch/x86/mm/guest_walk_4.c
@@ -0,0 +1,2 @@
+#define GUEST_PAGING_LEVELS 4
+#include "guest_walk.c"
diff --git a/xen/arch/x86/mm/hap/Makefile b/xen/arch/x86/mm/hap/Makefile
index c6d296b51720..32aef9b4ba26 100644
--- a/xen/arch/x86/mm/hap/Makefile
+++ b/xen/arch/x86/mm/hap/Makefile
@@ -4,12 +4,3 @@ obj-y += guest_walk_3level.o
 obj-y += guest_walk_4level.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 $@
diff --git a/xen/arch/x86/mm/hap/guest_walk.c b/xen/arch/x86/mm/hap/guest_walk.c
index f59ebc84a290..832a8058471e 100644
--- a/xen/arch/x86/mm/hap/guest_walk.c
+++ b/xen/arch/x86/mm/hap/guest_walk.c
@@ -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_2level.c b/xen/arch/x86/mm/hap/guest_walk_2level.c
new file mode 100644
index 000000000000..defcd59bc260
--- /dev/null
+++ b/xen/arch/x86/mm/hap/guest_walk_2level.c
@@ -0,0 +1,2 @@
+#define GUEST_PAGING_LEVELS 2
+#include "guest_walk.c"
diff --git a/xen/arch/x86/mm/hap/guest_walk_3level.c b/xen/arch/x86/mm/hap/guest_walk_3level.c
new file mode 100644
index 000000000000..1c9eca37741e
--- /dev/null
+++ b/xen/arch/x86/mm/hap/guest_walk_3level.c
@@ -0,0 +1,2 @@
+#define GUEST_PAGING_LEVELS 3
+#include "guest_walk.c"
diff --git a/xen/arch/x86/mm/hap/guest_walk_4level.c b/xen/arch/x86/mm/hap/guest_walk_4level.c
new file mode 100644
index 000000000000..aa3900338a2d
--- /dev/null
+++ b/xen/arch/x86/mm/hap/guest_walk_4level.c
@@ -0,0 +1,2 @@
+#define GUEST_PAGING_LEVELS 4
+#include "guest_walk.c"
diff --git a/xen/arch/x86/mm/shadow/Makefile b/xen/arch/x86/mm/shadow/Makefile
index fd64b4dda925..b4a1620b6920 100644
--- a/xen/arch/x86/mm/shadow/Makefile
+++ b/xen/arch/x86/mm/shadow/Makefile
@@ -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
index 000000000000..288b229982b0
--- /dev/null
+++ b/xen/arch/x86/mm/shadow/guest_2.c
@@ -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
index 000000000000..04e17b0b8adc
--- /dev/null
+++ b/xen/arch/x86/mm/shadow/guest_3.c
@@ -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
index 000000000000..c0c5d3cb11ad
--- /dev/null
+++ b/xen/arch/x86/mm/shadow/guest_4.c
@@ -0,0 +1,2 @@
+#define GUEST_PAGING_LEVELS 4
+#include "multi.c"
diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c
index 8bb028c2e2fa..7207fcf9e75f 100644
--- a/xen/arch/x86/mm/shadow/multi.c
+++ b/xen/arch/x86/mm/shadow/multi.c
@@ -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>
diff --git a/xen/tools/symbols.c b/xen/tools/symbols.c
index 0b124526165d..710e9785d348 100644
--- a/xen/tools/symbols.c
+++ b/xen/tools/symbols.c
@@ -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;
-- 
Anthony PERARD



  parent reply	other threads:[~2021-07-01 14:10 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-01 14:09 [XEN PATCH v6 00/31] xen: Build system improvements Anthony PERARD
2021-07-01 14:09 ` [XEN PATCH v6 01/31] build: fix %.s: %.S rule Anthony PERARD
2021-07-05 14:40   ` Jan Beulich
2021-07-01 14:09 ` [XEN PATCH v6 02/31] build: introduce cpp_flags macro Anthony PERARD
2021-07-07 14:18   ` Jan Beulich
2021-07-12 10:53     ` Anthony PERARD
2021-07-01 14:09 ` [XEN PATCH v6 03/31] build: use if_changed on built_in.o Anthony PERARD
2021-07-08 12:03   ` Andrew Cooper
2021-07-12 11:08     ` Anthony PERARD
2021-07-01 14:09 ` [XEN PATCH v6 04/31] build: use if_changed_rules with %.o:%.c targets Anthony PERARD
2021-07-01 14:09 ` [XEN PATCH v6 05/31] build: factorise generation of the linker scripts Anthony PERARD
2021-07-07 14:25   ` Jan Beulich
2021-07-12 11:02     ` Anthony PERARD
2021-07-13  7:28       ` Jan Beulich
2021-07-01 14:09 ` Anthony PERARD [this message]
2021-07-07 14:45   ` [XEN PATCH v6 06/31] x86/mm: avoid building multiple .o from a single .c file Jan Beulich
2021-07-12 12:49     ` Anthony PERARD
2021-07-13  7:32       ` Jan Beulich
2021-07-01 14:09 ` [XEN PATCH v6 07/31] build,include: rework compat-build-source.py Anthony PERARD
2021-07-07 14:58   ` Jan Beulich
2021-07-12 14:35     ` Anthony PERARD
2021-07-13  7:37       ` Jan Beulich
2021-07-01 14:09 ` [XEN PATCH v6 08/31] build,include: rework compat-build-header.py Anthony PERARD
2021-07-01 14:09 ` [XEN PATCH v6 09/31] build: clean "lib.a" Anthony PERARD
2021-07-07 15:03   ` Jan Beulich
2021-07-12 14:42     ` Anthony PERARD
2021-07-01 14:09 ` [XEN PATCH v6 10/31] build: use $(kconfig) shortcut in clean rule Anthony PERARD
2021-07-07 15:05   ` Jan Beulich
2021-07-01 14:09 ` [XEN PATCH v6 11/31] build: fix clean targets when subdir-y is used Anthony PERARD
2021-07-07 15:15   ` Jan Beulich
2021-07-12 14:54     ` Anthony PERARD
2021-07-01 14:09 ` [XEN PATCH v6 12/31] build: use subdir-y in test/Makefile Anthony PERARD
2021-07-07 15:26   ` Jan Beulich
2021-07-12 15:22     ` Anthony PERARD
2021-07-13  7:41       ` Jan Beulich
2021-07-13 14:35         ` Anthony PERARD
2021-07-01 14:09 ` [XEN PATCH v6 13/31] build,tools: have default rules depends on symbols Anthony PERARD
2021-07-07 15:28   ` Jan Beulich
2021-07-01 14:09 ` [XEN PATCH v6 14/31] build,arm: move LDFLAGS change to arch.mk Anthony PERARD
2021-07-01 14:09 ` [XEN PATCH v6 15/31] build: move make option changes check earlier Anthony PERARD
2021-07-07 15:40   ` Jan Beulich
2021-07-12 16:21     ` Anthony PERARD
2021-07-13  7:42       ` Jan Beulich
2021-07-01 14:09 ` [XEN PATCH v6 16/31] build: avoid building arm/arm/*/head.o twice Anthony PERARD
2021-07-01 14:09 ` [XEN PATCH v6 17/31] build: convert binfile use to if_changed Anthony PERARD
2021-07-07 15:48   ` Jan Beulich
2021-07-12 16:32     ` Anthony PERARD
2021-07-13  7:51       ` Jan Beulich
2021-07-13 14:58         ` Anthony PERARD
2021-07-13 15:33           ` Jan Beulich
2021-07-01 14:09 ` [XEN PATCH v6 18/31] xen: move include/asm-* to include/arch-*/asm Anthony PERARD
2021-07-01 17:24   ` Paul Durrant
2021-07-01 17:26   ` Bob Eshleman
2021-08-05  7:04   ` Jan Beulich
2021-08-09 13:20     ` Anthony PERARD
2021-07-01 14:09 ` [XEN PATCH v6 19/31] build: rework .banner generation Anthony PERARD
2021-08-05  7:09   ` Jan Beulich
2021-08-09 13:31     ` Anthony PERARD
2021-07-01 14:10 ` [XEN PATCH v6 20/31] build: generate "include/xen/compile.h" with filechk Anthony PERARD
2021-08-05  7:20   ` Jan Beulich
2021-08-09 14:27     ` Anthony PERARD
2021-07-01 14:10 ` [XEN PATCH v6 21/31] build: set XEN_BUILD_EFI earlier Anthony PERARD
2021-08-05  7:27   ` Jan Beulich
2021-08-09 15:59     ` Anthony PERARD
2021-08-10  7:44       ` Jan Beulich
2021-07-01 14:10 ` [XEN PATCH v6 22/31] build: fix $(TARGET).efi creation in arch/arm Anthony PERARD
2021-07-01 14:10 ` [XEN PATCH v6 23/31] build: fix arch/x86/node.o rule Anthony PERARD
2021-07-07 16:04   ` Jan Beulich
2021-07-01 14:10 ` [XEN PATCH v6 24/31] build: set ALL_OBJS to main Makefile; move prelink.o to main Makefile Anthony PERARD
2021-07-01 14:10 ` [XEN PATCH v6 25/31] build: remove unneeded deps of x86_emulate.o Anthony PERARD
2021-08-06 16:06   ` Jan Beulich
2021-08-09 16:02     ` Anthony PERARD
2021-07-01 14:10 ` [XEN PATCH v6 26/31] build: clean common temporary files from root makefile Anthony PERARD
2021-07-01 14:10 ` [XEN PATCH v6 27/31] build: prepare to always invoke $(MAKE) from xen/, use $(obj) Anthony PERARD
2021-07-01 14:10 ` [XEN PATCH v6 28/31] build: rework test/livepatch/Makefile Anthony PERARD
2021-07-01 14:10 ` [XEN PATCH v6 29/31] build: build everything from the root dir, use obj=$subdir Anthony PERARD
2021-07-01 17:49   ` Bob Eshleman
2021-07-01 14:10 ` [XEN PATCH v6 30/31] build: introduce if_changed_deps Anthony PERARD
2021-07-01 14:10 ` [XEN PATCH v6 31/31] build,riscv: tell the build system about riscv64/head.S Anthony PERARD
2021-07-01 17:52   ` Bob Eshleman
2021-07-02  4:45   ` Alistair Francis
2021-07-10  0:50   ` Connor Davis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210701141011.785641-7-anthony.perard@citrix.com \
    --to=anthony.perard@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=iwj@xenproject.org \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.