From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id E80D83854571 for ; Thu, 17 Nov 2022 18:13:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E80D83854571 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-oi1-x22f.google.com with SMTP id h132so2768514oif.2 for ; Thu, 17 Nov 2022 10:13:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=jesFHX6D+XuTYok+15afRrv/x9bPyuNa8nUmfhXv0Mc=; b=uvIVYqEB1fqj4W7lEoQIFZfpFXAxjpugSern7jax7WFYekp1eTLVUFPDzM18GmKAys LtpDRdSCLPmYSP8kUN7EEx3JVYS3C4I0bfbsJ4FhkLswEnf0BUM/eWulbvt03FgfK5lc YB6c5dN40xRDKrRdA+T4pZGgU9WtqfQ/UmKBhzfqJ66wG47KsHY2tKYsEmQBrmEu2PfS /OA1cEFhYKMUO6dKg8JfUB4AAYg2THPJSlfoJonlhVJ6SLw+ranhErw1oWQM451uKUVU p6jTfJXWr6sPCuobTXMdzUplfVfTePCYO2eXUiH9e4fbOu+kLdSd3MN4vZjHsI6g9VKv 5X0A== 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=jesFHX6D+XuTYok+15afRrv/x9bPyuNa8nUmfhXv0Mc=; b=UrV7K0PJRxCdsh9b+q5a3PBoMNmNUZLwiSCm0ByMRnPj3nFTSJ506c2PfQ/Yx1pnON OMHSEW6Qgs/WVRGRU9Qx4cUjLz9zC3WbBs88OrEs2uwnOiKZWbpeCT1zLxRZWem9JSBD B4JAuhgfOYSo+Pl2tdiYp4+trjK04mJ6sT7i752zSjkubdd9GNGx9PhrQveBYJDQALBR S0NenYl1vvRZoQUGcVMri2yUHEHy/Pfn1plBVmrNWQCB+ccd9hA/tqsFRkHeHsbEu9HS NUaKoCSJtQT3vCdXZEs1iKed7USrF9BTnwLb0gAHMUilDoI/1YbA3n0SXCt6x+eZS9KG U+Og== X-Gm-Message-State: ANoB5pnLeylr1Fy7OVLWvIiZodORD5YKSxaDZoN2g2hyXtQsF2a8kaxv /acU7kpM8C5hE2WkVnxAJksdP2bYjsawclyl X-Google-Smtp-Source: AA0mqf60eMp7z5JTEPJAt0YUFsThXwsALuqJChIlAxPzOJcG7nZK8gp8Nl4tQDmetH3QodItadNgEg== X-Received: by 2002:aca:f156:0:b0:35a:6bf8:e331 with SMTP id p83-20020acaf156000000b0035a6bf8e331mr1742686oih.125.1668708792141; Thu, 17 Nov 2022 10:13:12 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:84f3:2ecb:33cc:fbb6:e247]) by smtp.gmail.com with ESMTPSA id n9-20020a056870558900b0013669485016sm747538oao.37.2022.11.17.10.13.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 10:13:11 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Fangrui Song , "H . J . Lu" Subject: [PATCH v2] i386: Avoid avoid rely on linker optimization to avoid relocation Date: Thu, 17 Nov 2022 15:13:08 -0300 Message-Id: <20221117181308.1761316-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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: 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..23e4f2b012 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@PLT +#endif END (_start) /* To fulfill the System V/i386 ABI we need this symbol. Yuck, it's so -- 2.34.1