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.6 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,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 79EE71F910 for ; Thu, 17 Nov 2022 12:43:49 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="kjki5R03"; dkim-atps=neutral Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D54C039960C8 for ; Thu, 17 Nov 2022 12:43:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D54C039960C8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668689024; bh=i8Vhg8mgIdPd9diMXToRl2IUsLtW8Oz+rDh+b3ls5Hs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=kjki5R037OAH+4lMi+UPc7xcl6e/rBvgdlBd3HEipgPWdOVNk4XMmJDqwouAiQJAU oPMbylEiln7b7nRU2f0kQoOOXuyi41jziyYGZHJDPoiDOpU21uWSdH6OB/VJdXBWmj iT88Lq2SX6DT4p5mgyMFA8m/+wa+0nszOfuG1+/Y= Received: from mail-oa1-x2f.google.com (mail-oa1-x2f.google.com [IPv6:2001:4860:4864:20::2f]) by sourceware.org (Postfix) with ESMTPS id DE745398AC39 for ; Thu, 17 Nov 2022 12:43:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DE745398AC39 Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-1322d768ba7so1990736fac.5 for ; Thu, 17 Nov 2022 04:43:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=i8Vhg8mgIdPd9diMXToRl2IUsLtW8Oz+rDh+b3ls5Hs=; b=ksUaBEB4B7103KdDcZjjGOreQRAXB2yAea8cyMNOzXxxCFiXdkIDY5B3e2u98Lvc31 0wLMss/ew/ZSNvob3KRgr2I3lQAJr+oAw+6muupnKmmG+e1wPtwAxbMNLYLnXKNOrreo +jOlqAwp2h8s7Oa3vfKb11+QJ/9qwJUp7A8vGLOH48zQ45ISFN1ZbDdwKo/83RjVD67A wXaC+oFM0JfXeBd330FSKQbM7xnMi1Fzuk98hXYP1U91xYS1NnnJ05xDIdTU4ID6KDEw DH3HN9Jnd6IdTY50KLoBVTm3XFyx7qrDNILJDF8NIUVVkRKaNCuKyFoy5CPQQ3LV2r1V 2hfw== X-Gm-Message-State: ANoB5pmFzKeEv/HGYEUgdOCCDZgD54Ax9Wpa7+ytqsJ8g9iWqBZZDtij ETW6J/Ut7yOawyndHoUudWLZubqFFvfQI7yI X-Google-Smtp-Source: AA0mqf6l/vJEYcAjRiJEFThGMOiM+f7pWMJKdwb8eyIFU4oHbVolmC/Y+kCDAyhraSthlSaw67pIZQ== X-Received: by 2002:a05:6870:428a:b0:132:4f85:df90 with SMTP id y10-20020a056870428a00b001324f85df90mr4144135oah.288.1668689001821; Thu, 17 Nov 2022 04:43:21 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:84f3:2ecb:33cc:fbb6:e247]) by smtp.gmail.com with ESMTPSA id d9-20020a4ad349000000b0049f3bdd791esm269903oos.26.2022.11.17.04.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 04:43:21 -0800 (PST) To: libc-alpha@sourceware.org, Fangrui Song , "H . J . Lu" Subject: [PATCH] i386: Avoid avoid rely on linker optimization to avoid relocation Date: Thu, 17 Nov 2022 09:43:17 -0300 Message-Id: <20221117124317.2816607-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 via Libc-alpha Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" 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 +#endif END (_start) /* To fulfill the System V/i386 ABI we need this symbol. Yuck, it's so -- 2.34.1