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

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


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 5 May 2022 13:44:13 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.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=YzAUuUk5ZHPwsHZGXAwqO9Q/Yk3SDydaDJ7ipfYDrYM=; b=asbRIRmD5oMLn5mLCuQ20DlA7S32ZqV1gYuxAhJ1Oe2ELEi+dkzE/bTJw8+blCmaskOH5AR6/+hFZ8eMMBc2frEhUJcFaTb4sCuUaScyMqgQadiLrnIYIlAsVlpZ3QDYUdZiqJmkmdSlF/OpK+JVqMq/I9lo1cdezVhR0Qb2RrYqkU3OYvHBG7iL8CF4l7cW84t/A9cjYiV23+IjNPoVwmrDNCSYyGl/2QslV9e5IpWuErwJum+GXMxz52gL/GXfpvfvfKxETOFbgYDpZkb7wCd3qCnGruHYcFjQgSPgd0ckPP3fjFXkm6PBzllemui+CY4uhQF2wD5PDSPUKCjrUA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N7/E1HqGS4RywRK9/BHN1nbYja8ZWU+/DrIx4IbcE/AWKLKWp2mqTYUtdmachSm+6gnLO3UXK9huqhFtp/zEo0bVylmxIGmiO8Q62k2EEGRGnN8UBXHM8i/ykL6m7euwZYRGe1cI3RWVk1tiKZvWBta5WNb4uabF4Ky3AaL2YRVEdXs76UgLQKAV/aS5euVWvynkCcf3y7hw5qOCLPzUHqtdqQzKxLduxst5nayk1KkNGU9KpGilY8MAy4GKF9vpuocJz1YBSEaT6S5EsMYhtwcwShbZT15tO4Uq8j3mUYx4/J1GNkLelu0qGo5M+5hbAWMBUXpfg3g46dttkNoDyQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Thu, 05 May 2022 11:44:39 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 05.05.2022 10:39, Roger Pau Monné wrote:
> On Tue, May 03, 2022 at 10:17:44AM +0200, Jan Beulich wrote:
>> On 02.05.2022 17:20, Roger Pau Monne wrote:
>>> 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
>>
>> I'm puzzled by "almost" - is there a pattern of which ones aren't
>> converted?
>>
>> Also "last linking step" is ambiguous, as we link three binaries and
>> aiui the issue is present on every of these passes. May I suggest
>> "... when linking actual executables" or (still somewhat ambiguous)
>> "... when linking final binaries"?
>>
>>> 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.
>>
>> Perhaps a map file (like we use for shared libraries in tools/) would
>> allow doing so? But of course this would want to be machine-generated,
>> not manually maintained.
>>
>> Have you gained any insight into _why_ they are doing what they do?
> 
> So after raising this in the LLVM LD forum, I was told this behavior
> is due to the spec:
> 
> "A hidden symbol contained in a relocatable object must be either
> removed or converted to STB_LOCAL binding by the link-editor when the
> relocatable object is included in an executable file or shared
> object."
> 
> Then I did some search myself and found that you raised the same with
> GNU ld not doing the conversion:
> 
> https://sourceware.org/bugzilla/show_bug.cgi?id=12374

Hmm, interesting. Too long ago to remember, but yes.

> So it seems LLVM LD goes a bit further than GNU ld and also changes
> the binding of symbols in the .symtab.  I'm not sure I would consider
> the behavior of either linkers wrong.

I agree (taking into account Alan's comment in the bug report above).

> As a test I've attempted to disable the hidden visibility setting we
> set in compiler.h, just to realize that parts of our code do rely on
> having hidden visibility.  That's the bug and alternative constructs
> that use the "i" asm constrain with function pointers.  That's only
> possible in the absence of a GOT or PLT table:
> 
> https://godbolt.org/z/jK3bq4fhe

Right, -fpic would then also need to go away.

> So I think the way to fix this would be to set the visibility to
> protected instead of hidden,

Originally, when we introduced the use of hidden, it was pretty clear
that protected would suffice, but using hidden seemed more logical.
Now that we have a reason where hidden ends up being too strict, I
agree we can switch to protected.

> and then to also make the setting of the
> visibility unconditional: the compiler not supporting -fvisibility and
> Xen not setting it will just lead to compiler errors further on during
> the build process.

I guess this being conditional pre-dates our requiring of gcc 4.1,
as that version looks to support both the command line option and
the pragma we use. So switching to making this unconditional ought to
be fine.

Jan




 


Rackspace

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