From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-4.4 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id B124B1F910 for ; Thu, 17 Nov 2022 16:53:38 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="hbY6cGJY"; dkim-atps=neutral Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B6A76384275E for ; Thu, 17 Nov 2022 16:53:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B6A76384275E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668704016; bh=/29g/YUISzrwIaIacprrcgwYD/xsX/SYLx4xSx7T/2o=; h=Date:Subject:To:Cc:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=hbY6cGJYw68W30xHZVOrOaVf4wTO+gCaifaCotTXaGC8XppEgYv1W7H1oI6cQiJhe +H091U4ODxPlAu7r07QjM+t1ZdE5Em+foDnetsRgQPc6osHN87d4R7oXcZhASQBXVq kOvsUT8hWoZF6VJ1gX61hJ08cU3rHTUAciRrSaRo= 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 Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-13c2cfd1126so2752150fac.10 for ; Thu, 17 Nov 2022 08:42:38 -0800 (PST) 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 Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Adhemerval Zanella Netto via Libc-alpha Reply-To: Adhemerval Zanella Netto Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" 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.