From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) by sourceware.org (Postfix) with ESMTPS id 4EE5B3831CF3 for ; Thu, 17 Nov 2022 16:42:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4EE5B3831CF3 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-13c2cfd1126so2752150fac.10 for ; Thu, 17 Nov 2022 08:42:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:organization:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=/29g/YUISzrwIaIacprrcgwYD/xsX/SYLx4xSx7T/2o=; b=piHESIXDF7k6Vr05wscTgQKsUYh2j4OyebzHTgtb2e0FNsloyuU61Mnv/Q+fB7deUk 44x8Rgy/e3YGP74QAmimP1dVBdfiuecBg9b1Vx40TMsId9gteCqZPkPnlC/edAyZEclE 8yZ1KE8OzW6QgHfmjH+U+opqEp3Kb1hpnfB0YE1u4okkoJHtwvG1mhp9SHbrvK+e7TrU v9k4tnmPP6yoDwrVGtkqmbkdW9ietqQJkLppWtHjNGklFaPDx/vmSm57CP8JrVch7/F7 BtvGUwNQkcbfzamFTnp5IjmBJg1UERsPMueh02xlAq6ZCLs4YRTK4amAbrf53J0jVO8W SvuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/29g/YUISzrwIaIacprrcgwYD/xsX/SYLx4xSx7T/2o=; b=PzvXbzkhqie7+0OB2GcDqhhMKsfPouxVQCDxFgcN0n9ox1uwKs50zb97PFjLJItZY+ geXF8s98muG6VxPLSmXnvhcnYqQFyq0Prk9/GYgVJxfg5pK96+y97fsPeRgXgmDzTZrz aRgvGdYipAYhCP4kIujdEunNkYlrP0r7VzH7P7U9GC+6DR4usacPEztozOVm12C3iMq6 hkqqPWc4kL/edPxigIiZidocwihb9uT6v4W6q8zn78T9PDBOT8dBzlXAYJd8Ci5by+Mg VuAbPIHoWWkfxyEKmNUAoftjSM/VjuIFG5yt3REwjk11Ghmxl/mjK7vqtFUoVNL1NlTk nWVA== X-Gm-Message-State: ANoB5plFBhI21aAjeAbJX9YhIdtW1j1KuFi4s8ow6kqg5LPfBBL9pmK6 4e+m2pvkAjXGTy5Z1Z0T5optmg== X-Google-Smtp-Source: AA0mqf67UIKKx4OahCBN5+pfisnHv/idvFdZC+Td/9gg2eY/UetfXHRce8dhkJFSVr7WQoxxJh2z4g== X-Received: by 2002:a05:6870:f816:b0:13b:1167:b7c9 with SMTP id fr22-20020a056870f81600b0013b1167b7c9mr1686096oab.289.1668703357531; Thu, 17 Nov 2022 08:42:37 -0800 (PST) Received: from [192.168.15.31] ([177.103.70.31]) by smtp.gmail.com with ESMTPSA id v12-20020a4ae6cc000000b0049fbd80e522sm356589oot.23.2022.11.17.08.42.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Nov 2022 08:42:37 -0800 (PST) Message-ID: <70206245-247a-009b-cd39-a010e86af5b2@linaro.org> Date: Thu, 17 Nov 2022 13:41:19 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH] i386: Avoid avoid rely on linker optimization to avoid relocation To: "H.J. Lu" Cc: libc-alpha@sourceware.org, Fangrui Song References: <20221117124317.2816607-1-adhemerval.zanella@linaro.org> Content-Language: en-US From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,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 17/11/22 13:07, H.J. Lu wrote: > 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"? My understanding is for static build we can handle main as hidden, so there is no need use a PLT relocation here.