From patchwork Fri Jan 31 03:04:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 105709 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9483F3858C52 for ; Fri, 31 Jan 2025 04:43:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9483F3858C52 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=Ikl9RFUF X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id B57763858D21 for ; Fri, 31 Jan 2025 04:42:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B57763858D21 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B57763858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::634 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1738298529; cv=none; b=OvXJU2yg+3TFB9JvT1kQIxNnVDqCX5pDAooTp7R+jMgZyEkTgcoZ0bhMUWiTAcJ9pI2jx/rEe22rREAOXNkaNQ3XcFEifcVfZikIYM2uRr6gpRENsv2q37eNViSRUiteI63ef0SvJXDe/a7R5MbFaiMg424N43YrWKxNzPyAHR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1738298529; c=relaxed/simple; bh=oRNnl+hqZhGcU+ZZSkGOkaaprd2cfYdhQmdPanuuCLU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tyUG+fBmQnN+qCIl+dbsUEZTEcUwy3r9s2wkQvvk7MhuxtK7uKE0LIgvp/RS4wJWddFUxgenHfcWZ7QN35LMLz/le8HBJrIBzPPaomTxq+SkBRxhEeiBlOxRMR9NF+9ajO7w34YuSxBCK5zLFgaQFqO3zcv40BC138r8jm1wQ6c= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B57763858D21 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2156e078563so22529475ad.2 for ; Thu, 30 Jan 2025 20:42:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1738298529; x=1738903329; darn=sourceware.org; h=mime-version:user-agent:message-id:date:organization:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=6JARI447Gm72cUY8HVZBMv2V9fv+//O8/ktQmoWaHbA=; b=Ikl9RFUFyx//8WEip+8bSX/wF37JRYuEoLKVe88GrlfAqBGsFYhxVjLQ7fvzGZoo5g /1ZO0/mcLyz8vRVbk7PTKjSmdiBPSdoE62Sxnwjpcr/Uk5sxV0wshELH0Z5wQmXjOMaN 7MNbbJSQjfGmhVuoMDMkruhI/ptnD6Opslc4+3SOt+mOiB/Z6CpudxlFc/GHtor3o62H SlAhY3b4EY5m9HQ8kTMvDET+U3GS85xjmpNCAmc8OIkHG2T/+YgDUroiEu1cb8yvoS7j /4JHOLvYhrzkaYff5Aii4tM/0Uqoc4IFL7+zaaEln+EABM5mEeKZeaLiYiTh4BpCB53X 3pJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738298529; x=1738903329; h=mime-version:user-agent:message-id:date:organization:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6JARI447Gm72cUY8HVZBMv2V9fv+//O8/ktQmoWaHbA=; b=GLzIM14i2bzOZEUEmPSmWuDy2SLqhiOKHRngSJQj3+rgoPiX7iwtQRuTtoGnXSrhpP 5xWKNGLHmj3eaCHkow8cpulnS0UxI24xSF4SxpOMGS48M/tVrOLj4iWOx1EBcZ/Fm5Dk 4Cr3aUxKt1eqkt6zx6AupQSe03e6vYjik9t4XWi7zpsFcWkSKIEH3OJJoufZfoH5VCsT 22CDYcV9Yn7fUPA3xDoR9qrcvKix2ms6FaSu7GOQTA3Nf/qfl8+4Qu6/10END9Hb6lIB mXjiNkucrDIP1k4wrrFl7Hi8cQLQ3epepukOlbeXL0Wfmeou4jPbC4RFu8SHr/2ZUEVb MxgA== X-Gm-Message-State: AOJu0YxzocgMLyRf/yb+5Nu9gd+sl2e+UIUgBVikAMZvFNxM5Or2Abxc WgOgaIJAbd6MBckTqyFBZiZNerh7+YzWqrMeeciNdBbkRqp8C02p9pRyxqdlUTPj9dkBhfBZY74 WLQ== X-Gm-Gg: ASbGncvK5nUr2yu5imaDVSyX1om5u2x9MeJky+fb04A+diMaskp50xa/HEXCodbu/9Z DCahWnW76Em4Xx9FewudPy0ga5Te2m/r68UKzj6k/jfIpXurs0IcgNsYPNgobN49ACju02MEO28 uGB5QISEH0SowQyeu3hV2TroYQubaIarANQ9pu14wwY3LW4XDcUFmw8+rc49W1fPZDZVGfiWUZh Tyuc4X8pPTlQ+kUxKQDxm0EYVEKrWt4D+lTBk8JsDWeo/Huft1X0o77I27P5mqkbR0iXwtHKxgH n3tbXwGiQI4= X-Google-Smtp-Source: AGHT+IHTYsLDvZQR6KLV4+7EOH4iTx43ripje6F4wwRupiJ60vTo7BTcf566Q2O9gsw5GoLFWzGhVA== X-Received: by 2002:a17:903:124b:b0:20b:8a71:b5c1 with SMTP id d9443c01a7336-21dd7c4641cmr135489335ad.1.1738298528660; Thu, 30 Jan 2025 20:42:08 -0800 (PST) Received: from free.home ([2804:7f1:218b:c849:faf6:c43c:ba6c:65d3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21de331fa4csm21655105ad.232.2025.01.30.20.42.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2025 20:42:08 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 50V34nvo1849486 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 31 Jan 2025 00:04:50 -0300 From: Alexandre Oliva To: binutils@sourceware.org Cc: "David S. Miller" , "Jose E. Marchesi" Subject: [PATCH] sparc: define _GLOBAL_OFFSET_TABLE_ when referenced Organization: Free thinker, does not speak for AdaCore Date: Fri, 31 Jan 2025 00:04:49 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.5 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, WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org GCC testsuite gcc.dg/20050321-2.c hit link errors on undefined _GLOBAL_OFFSET_TABLE_. The compiler output referenced only _GLOBAL_OFFSET_TABLE_-offsets to set it up, and to compute the GOT-relative address of local symbols, none of which triggered the machinery that enabled the creation of the dynamic section, so _GLOBAL_OFFSET_TABLE_ ended up undefined. Enable the dynamic section if we find a relocation involving _G_O_T_ that we'd otherwise ignore. Tested with --target=sparc-leon3-elf. Ok to install? for bfd/ChangeLog * elfxx-sparc.c (_bfd_sparc_elf_check_relocs): Create the got section upon finding a _GLOBAL_OFFSET_TABLE_-referencing relocation that we'd otherwise ignore. for ld/ChangeLog * testsuite/ld-sparc/got-def.s: New test. * testsuite/ld-sparc/sparc.exp: Add it. --- bfd/elfxx-sparc.c | 7 ++++++- ld/testsuite/ld-sparc/got-def.s | 15 +++++++++++++++ ld/testsuite/ld-sparc/sparc.exp | 8 ++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 ld/testsuite/ld-sparc/got-def.s diff --git a/bfd/elfxx-sparc.c b/bfd/elfxx-sparc.c index 71061621e8bfb..cec270e427acc 100644 --- a/bfd/elfxx-sparc.c +++ b/bfd/elfxx-sparc.c @@ -1647,7 +1647,12 @@ _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, if (h != NULL && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) - break; + { + if (!htab->elf.sgot + && !_bfd_elf_create_got_section (htab->elf.dynobj, info)) + return false; + break; + } /* Fall through. */ case R_SPARC_DISP8: diff --git a/ld/testsuite/ld-sparc/got-def.s b/ld/testsuite/ld-sparc/got-def.s new file mode 100644 index 0000000000000..efca9109dfcb1 --- /dev/null +++ b/ld/testsuite/ld-sparc/got-def.s @@ -0,0 +1,15 @@ + .text +.LLGETPC0: + retl + add %o7, %l7, %l7 + .global got + .type got, #function + .proc 04 +got: + save %sp, -160, %sp + sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %l7 + call .LLGETPC0 + add %l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7 + mov %l7, %o0 + ret + restore diff --git a/ld/testsuite/ld-sparc/sparc.exp b/ld/testsuite/ld-sparc/sparc.exp index 9d684899ee2c2..3e21ed738c443 100644 --- a/ld/testsuite/ld-sparc/sparc.exp +++ b/ld/testsuite/ld-sparc/sparc.exp @@ -94,6 +94,10 @@ set sparctests { {"32-bit: TLS -fpie" "-melf32_sparc -pie tmpdir/libtlslib32.so" "" "--32 -K PIC" {tlspie32.s} {{objdump -drj.text tlspie32.dd}} "tlspie32"} + {"32-bit: GOT definition" + "-melf32_sparc" "" + "--32 -K PIC" {got-def.s} + {} "got-def"} {"32-bit: GOTDATA relocations" "-shared -melf32_sparc --hash-style=sysv" "" "--32 -K PIC" {gotop32.s} @@ -134,6 +138,10 @@ set sparc64tests { "-melf64_sparc -pie -Ttext-segment=0x100000 tmpdir/libtlslib64.so" "" "--64 -Av9 -K PIC" {tlspie64.s} {{objdump -drj.text tlspie64.dd}} "tlspie64"} + {"64-bit: GOT definition" + "-melf64_sparc" "" + "--64 -Av9 -K PIC" {got-def.s} + {} "got-def"} {"64-bit: GOTDATA relocations" "-shared -melf64_sparc --hash-style=sysv" "" "--64 -Av9 -K PIC" {gotop64.s}