]> xenbits.xensource.com Git - people/hx242/xen.git/commitdiff
build: provide option to disambiguate symbol names
authorJan Beulich <jbeulich@suse.com>
Thu, 28 Nov 2019 16:47:25 +0000 (17:47 +0100)
committerJan Beulich <jbeulich@suse.com>
Thu, 28 Nov 2019 16:47:25 +0000 (17:47 +0100)
The .file assembler directives generated by the compiler do not include
any path components (gcc) or just the ones specified on the command line
(clang, at least version 5), and hence multiple identically named source
files (in different directories) may produce identically named static
symbols (in their kallsyms representation). The binary diffing algorithm
used by xen-livepatch, however, depends on having unique symbols.

Make the ENFORCE_UNIQUE_SYMBOLS Kconfig option control the (build)
behavior, and if enabled use objcopy to prepend the (relative to the
xen/ subdirectory) path to the compiler invoked STT_FILE symbols. Note
that this build option is made no longer depend on LIVEPATCH, but merely
defaults to its setting now.

Conditionalize explicit .file directive insertion in C files where it
exists just to disambiguate names in a less generic manner; note that
at the same time the redundant emission of STT_FILE symbols gets
suppressed for clang. Assembler files as well as multiply compiled C
ones using __OBJECT_FILE__ are left alone for the time being.

Since we now expect there not to be any duplicates anymore, also don't
force the selection of the option to 'n' anymore in allrandom.config.
Similarly COVERAGE no longer suppresses duplicate symbol warnings if
enforcement is in effect, which in turn allows
SUPPRESS_DUPLICATE_SYMBOL_WARNINGS to simply depend on
!ENFORCE_UNIQUE_SYMBOLS.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Wei Liu <wl@xen.org>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Tested-by: Sergey Dyasli <sergey.dyasli@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
13 files changed:
xen/Kconfig.debug
xen/Rules.mk
xen/arch/x86/x86_64/compat.c
xen/arch/x86/x86_64/mm.c
xen/arch/x86/x86_64/physdev.c
xen/arch/x86/x86_64/platform_hypercall.c
xen/common/Kconfig
xen/common/compat/domain.c
xen/common/compat/kernel.c
xen/common/compat/memory.c
xen/common/compat/multicall.c
xen/include/xen/config.h
xen/tools/kconfig/allrandom.config

index 22573e74dbef749917441ab4dcbbd4fac42510d2..cf42e5e7a0d6b5cfe2768c0adaaaf235ada325d2 100644 (file)
@@ -38,7 +38,7 @@ config FRAME_POINTER
 config COVERAGE
        bool "Code coverage support"
        depends on !LIVEPATCH
-       select SUPPRESS_DUPLICATE_SYMBOL_WARNINGS
+       select SUPPRESS_DUPLICATE_SYMBOL_WARNINGS if !ENFORCE_UNIQUE_SYMBOLS
        ---help---
          Enable code coverage support.
 
index 3090ea78288f5962204c1c537435b0d95c944d04..b0bc7601c15c9051a2d7cd2e3d8dfb829ccb26b4 100644 (file)
@@ -194,12 +194,24 @@ FORCE:
 
 .PHONY: clean
 clean:: $(addprefix _clean_, $(subdir-all))
-       rm -f *.o *~ core $(DEPS_RM)
+       rm -f *.o .*.o.tmp *~ core $(DEPS_RM)
 _clean_%/: FORCE
        $(MAKE) -f $(BASEDIR)/Rules.mk -C $* clean
 
+SRCPATH := $(patsubst $(BASEDIR)/%,%,$(CURDIR))
+
 %.o: %.c Makefile
+ifeq ($(CONFIG_ENFORCE_UNIQUE_SYMBOLS),y)
+       $(CC) $(CFLAGS) -c $< -o $(@D)/.$(@F).tmp
+ifeq ($(clang),y)
+       $(OBJCOPY) --redefine-sym $<=$(SRCPATH)/$< $(@D)/.$(@F).tmp $@
+else
+       $(OBJCOPY) --redefine-sym $(<F)=$(SRCPATH)/$< $(@D)/.$(@F).tmp $@
+endif
+       rm -f $(@D)/.$(@F).tmp
+else
        $(CC) $(CFLAGS) -c $< -o $@
+endif
 
 %.o: %.S Makefile
        $(CC) $(AFLAGS) -c $< -o $@
index edc3115902a8a11c2e57016bba9819add2b3e59c..179d0c637ac2efcd7bf3cf74a57003ef14389323 100644 (file)
@@ -2,7 +2,7 @@
  * compat.c
  */
 
-asm(".file \"" __FILE__ "\"");
+EMIT_FILE;
 
 #include <xen/hypercall.h>
 #include <compat/xen.h>
index fa55f3474e0f81a404334f6b6de3c540c3e36082..8ea09ecc30ebb134f98608d9cf411bb3fb125a71 100644 (file)
@@ -16,7 +16,7 @@
  * with this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
-asm(".file \"" __FILE__ "\"");
+EMIT_FILE;
 
 #include <xen/lib.h>
 #include <xen/init.h>
index c5a00ea93f398b703f623e69666f51dd55ef6cac..0a50cbd4d8779a4f7f9c7d9f28c4cd2c9c2870ce 100644 (file)
@@ -2,7 +2,7 @@
  * physdev.c
  */
 
-asm(".file \"" __FILE__ "\"");
+EMIT_FILE;
 
 #include <xen/types.h>
 #include <xen/guest_access.h>
index 8fa2543a2d8ee82f12811a1e941236d454ef54be..fbba893a47cb5b610bbf2cf67daf4385c431fb56 100644 (file)
@@ -2,7 +2,7 @@
  * platform_hypercall.c
  */
 
-asm(".file \"" __FILE__ "\"");
+EMIT_FILE;
 
 #include <xen/lib.h>
 #include <compat/platform.h>
index f75474197273bcdf641fd959c4bdf31d6abd3cf2..2f516da10128d2630869485e74c406a93877ff88 100644 (file)
@@ -373,8 +373,7 @@ config FAST_SYMBOL_LOOKUP
 
 config ENFORCE_UNIQUE_SYMBOLS
        bool "Enforce unique symbols"
-       default y
-       depends on LIVEPATCH
+       default LIVEPATCH
        ---help---
          Multiple symbols with the same name aren't generally a problem
          unless livepatching is to be used.
@@ -387,8 +386,8 @@ config ENFORCE_UNIQUE_SYMBOLS
          livepatch build and apply correctly.
 
 config SUPPRESS_DUPLICATE_SYMBOL_WARNINGS
-       bool "Suppress duplicate symbol warnings" if !ENFORCE_UNIQUE_SYMBOLS
-       default y if !ENFORCE_UNIQUE_SYMBOLS
+       bool "Suppress duplicate symbol warnings"
+       depends on !ENFORCE_UNIQUE_SYMBOLS
        ---help---
          Multiple symbols with the same name aren't generally a problem
          unless Live patching is to be used, so these warnings can be
index 2531fa74214d6ccd8e5a45064467b1d130322de9..11c6afc46329650c7470f15025f18aba33fd843b 100644 (file)
@@ -3,7 +3,7 @@
  *
  */
 
-asm(".file \"" __FILE__ "\"");
+EMIT_FILE;
 
 #include <xen/lib.h>
 #include <xen/sched.h>
index 64232669d28fd28412e8a8b0693f64fc2b2324e0..5c6e7322f804bda5e30c69e916b7d10ea7bb1268 100644 (file)
@@ -2,7 +2,7 @@
  * kernel.c
  */
 
-asm(".file \"" __FILE__ "\"");
+EMIT_FILE;
 
 #include <xen/init.h>
 #include <xen/lib.h>
index 10a954f2815d32aa483d541fa7170090072ec797..3851f756c7b8865719322080e02d61dcf6e70a78 100644 (file)
@@ -1,4 +1,4 @@
-asm(".file \"" __FILE__ "\"");
+EMIT_FILE;
 
 #include <xen/types.h>
 #include <xen/hypercall.h>
index 43d2d8152dd2d88d5c1549d5484013e9c15dfa3c..a0e9918f4805653a45add52ea3babc2c381ae2f5 100644 (file)
@@ -2,7 +2,7 @@
  * multicall.c
  */
 
-asm(".file \"" __FILE__ "\"");
+EMIT_FILE;
 
 #include <xen/types.h>
 #include <xen/multicall.h>
index a106380a23604fdc15bf6aa83fefd0058298b2dc..b76222ecf6defff8896e63b35d29af38fa4766d1 100644 (file)
 
 #ifndef __ASSEMBLY__
 #include <xen/compiler.h>
+
+#if defined(CONFIG_ENFORCE_UNIQUE_SYMBOLS) || defined(__clang__)
+# define EMIT_FILE asm ( "" )
+#else
+# define EMIT_FILE asm ( ".file \"" __FILE__ "\"" )
+#endif
+
 #endif
+
 #include <asm/config.h>
 
 #define EXPORT_SYMBOL(var)
index c480896b967c1e2a945e4710ca341c25306a5b6b..76f74320b5b07eb9b5bf9e299ad070b7385ee536 100644 (file)
@@ -2,4 +2,3 @@
 
 CONFIG_GCOV_FORMAT_AUTODETECT=y
 CONFIG_UBSAN=n
-CONFIG_ENFORCE_UNIQUE_SYMBOLS=n