From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by sourceware.org (Postfix) with ESMTPS id 2226339960FC for ; Thu, 17 Nov 2022 16:08:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2226339960FC Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x534.google.com with SMTP id x2so3241594edd.2 for ; Thu, 17 Nov 2022 08:08:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=i1ZlWMBx/wpq6wTDMPtKaF71/sMhJffTJgMGtCiom9o=; b=lV59yGy1vMKzHyrPlSKRPyyTeUN7tbweDXtZOtXUMtig/9ZJtfRnUxESVna3yQt2dm rTrRjhA6bXEUjLfRaT2cKjFenU83w12ZUsm76d4EyRG9ZxphR2wor63253Zn1lRBC5Iv 2RJLS8uf6nD5QATQsIkTIormyYRinQUVG9toTgKP6+XfCgXK0EVviIW0x0rkoO2bWE19 Ppjw+Yne2qJ/CAL5qh7Th4qknt6D/BvB9SEmjUmHLM3lrroRYgDHBYAvM6davNdoPq44 66iwCMvTVPOwf4iai+/4ODe3mPx5JbuGv49O4lXDMK4lo+7XCJkADtvd+xc6pFzJl++5 kRUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=i1ZlWMBx/wpq6wTDMPtKaF71/sMhJffTJgMGtCiom9o=; b=f4K6IafN4kHL986Xd5eJgHJEA+vlMTIInBQilLghkElEmEXd0vizbMDXNoftYsd8ct spyQqCRoJ0sUHhQTh4EVHfwng0Cb+ISfRZ+SrFJDQZlK5VEf3nUAC1fP8HRq0JPzBkE6 1fLYrHgm221SuMr6603QO7TyOzGxd5HZpMuqDApmS1oC/STVX5MNW9KrZNNZGh+Pr6AU zSu0b7Efw+5WDPfwEcfChysCY1+N0xHcSzuHrgCp78xXAivlgMAnF8qnTMMOxVi9tN4j e8NcIGPmzIQmWAJHcDlRmiLDcsOTivzbymgwNwCx/B2Ht6HBuHy3Ki7suqB2tgSkGIXx DkpQ== X-Gm-Message-State: ANoB5plupI9yJHr9rZvqzzR30/RvjFOTVIgUwmt0euXYxwZYcTHxsgW3 r9xQCVyXeIPZkZtGuN/7Why4RzsHb3ZkHlLhFNk= X-Google-Smtp-Source: AA0mqf4zEBXcyprblfVjd2a6NIf0b5SvIpeNP1qejjjg42Ek/nn0ovF+ffUtmQnkx9SLYJ6Ai3vAD5BymcQDP1HoPQ8= X-Received: by 2002:aa7:cd1a:0:b0:459:f897:7940 with SMTP id b26-20020aa7cd1a000000b00459f8977940mr2690212edw.168.1668701304650; Thu, 17 Nov 2022 08:08:24 -0800 (PST) MIME-Version: 1.0 References: <20221117124317.2816607-1-adhemerval.zanella@linaro.org> In-Reply-To: <20221117124317.2816607-1-adhemerval.zanella@linaro.org> From: "H.J. Lu" Date: Thu, 17 Nov 2022 08:07:45 -0800 Message-ID: Subject: Re: [PATCH] i386: Avoid avoid rely on linker optimization to avoid relocation To: Adhemerval Zanella Cc: libc-alpha@sourceware.org, Fangrui Song Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3023.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, Nov 17, 2022 at 4:43 AM Adhemerval Zanella wrote: > > lld does not implement all the linker optimization to avoid the GOT > relocation as done by binutils (bfd/elf32-i386.c:elf_i386_convert_load_reloc). > The current 'movl main@GOT(%ebx), %eax' will then create a GOT > relocation when building with lld, which make static-pie status to > not being able to start the provided main function. > > The change uses a __wrap_main local symbol, which in turn calls main > (similar as used by aarch64 and s390x). > > Checked on i686-linux-gnu with binutils and lld. > --- > sysdeps/i386/start.S | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/sysdeps/i386/start.S b/sysdeps/i386/start.S > index 4ec04bdfd7..d593c4de00 100644 > --- a/sysdeps/i386/start.S > +++ b/sysdeps/i386/start.S > @@ -98,11 +98,10 @@ ENTRY (_start) > pushl main@GOT(%ebx) > # else > /* Avoid relocation in static PIE since _start is called before > - it is relocated. Don't use "leal main@GOTOFF(%ebx), %eax" > - since main may be in a shared object. Linker will convert > - "movl main@GOT(%ebx), %eax" to "leal main@GOTOFF(%ebx), %eax" > + it is relocated. This also avoid rely on linker optimization to > + transform 'movl main@GOT(%ebx), %eax' to 'leal main@GOTOFF(%ebx)' > if main is defined locally. */ > - movl main@GOT(%ebx), %eax > + leal __wrap_main@GOTOFF(%ebx), %eax > pushl %eax > # endif > > @@ -130,6 +129,12 @@ ENTRY (_start) > 1: movl (%esp), %ebx > ret > #endif > + > +#if defined PIC && !defined SHARED > +__wrap_main: > + _CET_ENDBR > + jmp main Shouldn't it be "jmp main@PLT"? > +#endif > END (_start) > > /* To fulfill the System V/i386 ABI we need this symbol. Yuck, it's so > -- > 2.34.1 > -- H.J.