[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH RFC] x86/lld: fix symbol map generation


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Mon, 2 May 2022 17:20:20 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vIWelanqbp4RinFXdsKwb8IPkD2GS6socD99HZAMs4Y=; b=DVICLoyN6fcarufQEsjokd6S5eeDJhkih/bHvz/JZLE2v+1ryDwMhA3M+7YtnJCGpKHqNNbMBeyJ0Fh9ZsNac6yfKD2iBkUMsT9WdlFo6csyUTflrGcL2ueisofbV/3WthEwhmKeW/yWoZrjT8LHjGdXiJMdKSGyMJgALGD02Rv+x8wHlDlR87stpATncPWnx7pZNHDCcV3qPlZIzDu+Ijn3QGkhSLoUD0P9nEm6BYIqrrsjjtsr7EbOJVE4BDkj/2jpC4e7/MRyEE1puPDjxZsed/rk+vNy4uAHm/RrZ7BVhYAGKchz2jsCSCUsRSGZMptQwsbJuRBwXxcvOvtTDA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i/73PCc3lX/nqVDqmLzheK9xYTfsjxQh4UqVttEj3/XQjCtWBTBXa0DMeQ7v/YQNFtKiaFu7xGEpjQGC+Td4ZcMsh5ttorxd0C8RtiSIklXUVEgh0zcwm3v8dg+YT37P3Kv8ormwUkoIu8zkMWp0+uynI6v1NhXWG716KLYVLiDVpqmhRpWXOgkU67wo9+RN0qAMgQpumwaY2yrkTblVn+dnG+ayIEUOxso7PuW+bnDvvR9fd39qNIJhQifdfBLyatWHiYxq8hXU2RasL0ggukUHMzrHqt7awYHLUaDRUbPDrdINSTdvLxIxndypWhlATl7fJTFHVH7Ne6rqemQAqg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Mon, 02 May 2022 15:20:45 +0000
  • Ironport-data: A9a23:Axbc2atX/3aXGsBvV/frEwwxpOfnVCJfMUV32f8akzHdYApBsoF/q tZmKW2FPPbfa2DzLYgnb4jl9BsEuZbdzt9lTFM9+Ho0RHkQ+JbJXdiXEBz9bniYRiHhoOOLz Cm8hv3odp1coqr0/0/1WlTZhSAgk/nOHNIQMcacUsxLbVYMpBwJ1FQywobVvqYy2YLjW17V4 4uryyHiEATNNwBcYzp8B52r8HuDjNyq0N/PlgVjDRzjlAa2e0g9VPrzF4noR5fLatA88tqBb /TC1NmEElbxpH/BPD8HfoHTKSXmSpaKVeSHZ+E/t6KK2nCurQRquko32WZ1he66RFxlkvgoo Oihu6BcRi8PG4DTg/tHbCB8UAhnJ6gc4Z3gC1ew5Jn7I03uKxMAwt1IJWRvZcgy3LkyBmtDs /sFNDoKcxaPwfqsx662QfVtgcJlK9T3OIQYuTdryjSx4fQOGMifBfmVo4AAmm5o2KiiHt6HD yYdQSBoYxnaJQVGJ38cCY4knffujX76G9FdgA3P9fdpvDOKpOB3+IjrHoSKVPmpeeFEtF66+ kXcwWXFXQ5PYbRzzhLAqBpAnNTnjS79HY4fCrC83vprm0GIgHweDgUMUlm2quX/jVSxM/pdI UEJ/islrYAp6VemCNL6WnWQv3qsrhMaHd1KHIUHBBqlz6PV50OTADcCRzsYMNg+7pZuG3oty 0ODmM7vCXp3qrqJRHmB97CS6zSvJSwSKmxEbigBJecY3+TeTEgIpkqnZr5e/GSd1LUZxRmYL +i2kRUD
  • Ironport-hdrordr: A9a23:2G5w4qn9eiKCat44pX6XbykjxS7pDfOximdD5ihNYBxZY6Wkfp +V8cjzhCWftN9OYhodcLC7V5Voj0msl6KdhrNhRYtKPTOWwVdASbsP0WKM+UyFJ8STzI5gPM RbAtVD4aPLfD9HZK/BiWHXcurIqOP3ipxA7t2uqkuFIzsaCJ2JuGxCe32m+wBNNX97LKt8MK DZyttMpjKmd3hSRsOnBkMdV+yGg9HQjprpbTMPGhZisWC1/HuVwY+/NyLd8gYVUjtJz7tn2W /Zkzbh7qHml/2g0BfT20La8pwTstr8zdloAtCKl6EuW3zRozftQL4kd6yJvTgzru3qwFE2kO PUqxNlBMh342O5RBDBnfNAszOQoQoG2jvH8xu1kHHjqcv2SHYREMxan79UdRPf9g4JoMx8+L gj5RPUi7NnSTf72Ajt7dnBUB9n0mCup2A5rOIVh3tDFaMDdb5qq5AF9k89KuZMIMvD0vFoLA BSNrCc2B4PGmnqL0wx/1MfiuBEZ05DUStvGSM5y4+oOzs/pgEK86JX/r1cop46zuNDd3B13Z W5Dk1WrsAxciZvV9MaOA4ge7rCNoWfe2O6DIqtSW6XZJ0vCjbql6PdxokTyaWDRKEopaFC66 gpFmko/lIPRw==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The symbol map generation (and thus the debug info attached to Xen) is
partially broken when using LLVM LD.  That's due to LLD converting
almost all symbols from global to local in the last linking step, and
thus confusing tools/symbols into adding a file prefix to all text
symbols, the results looks like:

Xen call trace:
   [<ffff82d040449fe8>] R xxhash64.c#__start_xen+0x3938/0x39c0
   [<ffff82d040203734>] F __high_start+0x94/0xa0

In order to workaround this create a list of global symbols prior to
the linking step, and use objcopy to convert the symbols in the final
binary back to global before processing with tools/symbols.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
I haven't found a way to prevent LLD from converting the symbols, so
I've come up with this rather crappy workaround.

Not applied to EFI, partially because I don't have an environment with
LLD capable of generating the EFI binary.

Obtaining the global symbol list could likely be a target on itself,
if it is to be shared between the ELF and the EFI binary generation.
---
 xen/arch/x86/Makefile | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 177a2ff742..f3817827bc 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -134,24 +134,34 @@ $(TARGET): $(TARGET)-syms $(efi-y) $(obj)/boot/mkelf32
 CFLAGS-$(XEN_BUILD_EFI) += -DXEN_BUILD_EFI
 
 $(TARGET)-syms: $(objtree)/prelink.o $(obj)/xen.lds
+       # Dump global text symbols before the linking step
+       $(NM) -pa --format=bsd $< | awk '{ if($$2 == "T") print $$3}' \
+           > $(@D)/.$(@F).global-syms
        $(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds -N $< $(build_id_linker) \
-           $(objtree)/common/symbols-dummy.o -o $(@D)/.$(@F).0
+           $(objtree)/common/symbols-dummy.o -o $(@D)/.$(@F).0.tmp
+       # LLVM LD has converted global symbols into local ones as part of the
+       # linking step, convert those back to global before using tools/symbols.
+       $(OBJCOPY) --globalize-symbols=$(@D)/.$(@F).global-syms \
+           $(@D)/.$(@F).0.tmp $(@D)/.$(@F).0
        $(NM) -pa --format=sysv $(@D)/.$(@F).0 \
                | $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
                >$(@D)/.$(@F).0.S
        $(MAKE) $(build)=$(@D) $(@D)/.$(@F).0.o
        $(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds -N $< $(build_id_linker) \
-           $(@D)/.$(@F).0.o -o $(@D)/.$(@F).1
+           $(@D)/.$(@F).0.o -o $(@D)/.$(@F).1.tmp
+       $(OBJCOPY) --globalize-symbols=$(@D)/.$(@F).global-syms \
+           $(@D)/.$(@F).1.tmp $(@D)/.$(@F).1
        $(NM) -pa --format=sysv $(@D)/.$(@F).1 \
                | $(objtree)/tools/symbols $(all_symbols) --sysv --sort 
$(syms-warn-dup-y) \
                >$(@D)/.$(@F).1.S
        $(MAKE) $(build)=$(@D) $(@D)/.$(@F).1.o
        $(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds -N $< $(build_id_linker) \
-           $(orphan-handling-y) $(@D)/.$(@F).1.o -o $@
+           $(orphan-handling-y) $(@D)/.$(@F).1.o -o $@.tmp
+       $(OBJCOPY) --globalize-symbols=$(@D)/.$(@F).global-syms $@.tmp $@
        $(NM) -pa --format=sysv $(@D)/$(@F) \
                | $(objtree)/tools/symbols --all-symbols --xensyms --sysv 
--sort \
                >$(@D)/$(@F).map
-       rm -f $(@D)/.$(@F).[0-9]* $(@D)/..$(@F).[0-9]*
+       rm -f $(@D)/.$(@F).[0-9]* $(@D)/..$(@F).[0-9]* $(@D)/.$(@F).global-syms
 ifeq ($(CONFIG_XEN_IBT),y)
        $(SHELL) $(srctree)/tools/check-endbr.sh $@
 endif
@@ -266,6 +276,7 @@ $(obj)/xen.lds $(obj)/efi.lds: $(src)/xen.lds.S FORCE
 clean-files := \
     include/asm/asm-macros.* \
     $(objtree)/.xen-syms.[0-9]* \
+    $(objtree)/.xen-syms.global-syms \
     $(objtree)/.xen.elf32 \
     $(objtree)/.xen.efi.[0-9]* \
     efi/*.efi
-- 
2.35.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.