From patchwork Thu Oct 24 13:31:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11209711 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5BE813B1 for ; Thu, 24 Oct 2019 13:32:39 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AC03A20663 for ; Thu, 24 Oct 2019 13:32:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AC03A20663 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iNdCf-0004QA-Go; Thu, 24 Oct 2019 13:31:01 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iNdCe-0004Q5-G6 for xen-devel@lists.xenproject.org; Thu, 24 Oct 2019 13:31:00 +0000 X-Inumbo-ID: 82e5d7f8-f662-11e9-beca-bc764e2007e4 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 82e5d7f8-f662-11e9-beca-bc764e2007e4; Thu, 24 Oct 2019 13:30:58 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D7428BB5F; Thu, 24 Oct 2019 13:30:56 +0000 (UTC) To: "xen-devel@lists.xenproject.org" From: Jan Beulich Message-ID: <542838a9-8e9d-f1e8-4f7e-af5fc75ba3fe@suse.com> Date: Thu, 24 Oct 2019 15:31:11 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 Content-Language: en-US Subject: [Xen-devel] [PATCH] build: provide option to disambiguate symbol names X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Wei Liu , Konrad Wilk , George Dunlap , Andrew Cooper , Tim Deegan , Julien Grall , Ian Jackson , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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. Provide a Kconfig option to 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. 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. Signed-off-by: Jan Beulich --- Kconfig change taken from "[PATCH v3 5/7] x86/livepatch: Fail the build if duplicate symbols exist". When re-basing onto that other patch I think we will also want to drop that other patch'es adjustment to allrandom.config again. The clang behavior may require further tweaking if different versions behave differently. Alternatively we could pass two --redefine-sym arguments to objcopy. --- a/xen/Rules.mk +++ b/xen/Rules.mk @@ -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 $( #include --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -16,7 +16,7 @@ * with this program; If not, see . */ -asm(".file \"" __FILE__ "\""); +EMIT_FILE; #include #include --- a/xen/arch/x86/x86_64/physdev.c +++ b/xen/arch/x86/x86_64/physdev.c @@ -2,7 +2,7 @@ * physdev.c */ -asm(".file \"" __FILE__ "\""); +EMIT_FILE; #include #include --- a/xen/arch/x86/x86_64/platform_hypercall.c +++ b/xen/arch/x86/x86_64/platform_hypercall.c @@ -2,7 +2,7 @@ * platform_hypercall.c */ -asm(".file \"" __FILE__ "\""); +EMIT_FILE; #include #include --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -338,9 +338,23 @@ config FAST_SYMBOL_LOOKUP If unsure, say Y. +config ENFORCE_UNIQUE_SYMBOLS + bool "Enforce unique symbols" + default LIVEPATCH + ---help--- + Multiple symbols with the same name aren't generally a problem + unless Live patching is to be used. + + Livepatch loading involves resolving relocations against symbol + names, and attempting to a duplicate symbol in a livepatch will + result in incorrect livepatch application. + + This option should be used to ensure that a build of Xen can have a + livepatch build and apply correctly. + config SUPPRESS_DUPLICATE_SYMBOL_WARNINGS - bool "Suppress duplicate symbol warnings" if !LIVEPATCH - default y if !LIVEPATCH + 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 --- a/xen/common/compat/domain.c +++ b/xen/common/compat/domain.c @@ -3,7 +3,7 @@ * */ -asm(".file \"" __FILE__ "\""); +EMIT_FILE; #include #include --- a/xen/common/compat/kernel.c +++ b/xen/common/compat/kernel.c @@ -2,7 +2,7 @@ * kernel.c */ -asm(".file \"" __FILE__ "\""); +EMIT_FILE; #include #include --- a/xen/common/compat/memory.c +++ b/xen/common/compat/memory.c @@ -1,4 +1,4 @@ -asm(".file \"" __FILE__ "\""); +EMIT_FILE; #include #include --- a/xen/common/compat/multicall.c +++ b/xen/common/compat/multicall.c @@ -2,7 +2,7 @@ * multicall.c */ -asm(".file \"" __FILE__ "\""); +EMIT_FILE; #include #include --- a/xen/include/xen/config.h +++ b/xen/include/xen/config.h @@ -11,7 +11,15 @@ #ifndef __ASSEMBLY__ #include + +#if defined(CONFIG_ENFORCE_UNIQUE_SYMBOLS) || defined(__clang__) +# define EMIT_FILE asm ( "" ) +#else +# define EMIT_FILE asm ( ".file \"" __FILE__ "\"" ) +#endif + #endif + #include #define EXPORT_SYMBOL(var)