From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id A440B3858C83 for ; Tue, 8 Feb 2022 00:03:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A440B3858C83 Received: by mail-pf1-x42e.google.com with SMTP id g8so5965056pfq.9 for ; Mon, 07 Feb 2022 16:03:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=NTCIoX2sUXYx09fNMc8WDpJnboePhO4DanmPg1K66eQ=; b=vAIho5KZsG0GjGdiY00SwsQVMOzh4jXPUISnRWHBMtvc+elf/r6yzOhcVNf/utd32D 1lO8UCLQMTPU0q/si1Cpt01l/fu9HbtgFIXx4xtfYLcRDjynBSmGmfnfoQ50r6Eqs4hh 9NXJ+v7VvRsZtT0CvVLxLiXBAvRfIGG2xX9jUQ9Qvh493pq/Ht4dghooFK8rNkOZJDcp LebwuNTbPRaxKCCj1CST6pJgBQA7/KYCnpyG8rcR5Mou3SD6t+stM1PZtPTm+X+psNhb bRL1mywTFyy2TLe0UEG61bpbGoTrAZdPJ9ygFAAB/vqSzO6nULCeh8iLamynq3uHGG7P pARA== X-Gm-Message-State: AOAM533yVSGYnbOCA0voVJftLE2wjLvyzmxMI8R8f8D9YeUZDfgzWgVX DfeUXhCBFR/DpJ8QL9IKHorS1gH3CCk= X-Google-Smtp-Source: ABdhPJx+N6Y3agsNxCMCHhBqYmZP5YDqvpQLblD1vumExDU0W8Ry5WF2Q4pSwBuK9gG3A7HZ3pquHQ== X-Received: by 2002:a63:735c:: with SMTP id d28mr1462886pgn.154.1644278604433; Mon, 07 Feb 2022 16:03:24 -0800 (PST) Received: from gnu-tgl-3.localdomain ([172.58.38.240]) by smtp.gmail.com with ESMTPSA id y191sm13312989pfb.114.2022.02.07.16.03.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 16:03:23 -0800 (PST) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id D9E79C03D1 for ; Mon, 7 Feb 2022 16:03:22 -0800 (PST) From: "H.J. Lu" To: binutils@sourceware.org Subject: [PATCH] i386: Allow GOT32 relocations against ABS symbols Date: Mon, 7 Feb 2022 16:03:22 -0800 Message-Id: <20220208000322.4108601-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3029.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Feb 2022 00:03:30 -0000 I am checking this into master branch and backporting it to 2.37/2.38 branches. H.J. --- GOT32 relocations are allowed since absolute value + addend is stored in the GOT slot. Tested on glibc 2.35 build with GCC 11.2 and -Os. bfd/ PR ld/28870 * elfxx-x86.c (_bfd_elf_x86_valid_reloc_p): Also allow GOT32 relocations. ld/ PR ld/28870 * testsuite/ld-i386/i386.exp: Run pr28870. * testsuite/ld-i386/pr28870.d: New file. * testsuite/ld-i386/pr28870.s: Likewise. --- bfd/elfxx-x86.c | 10 ++++++---- ld/testsuite/ld-i386/i386.exp | 1 + ld/testsuite/ld-i386/pr28870.d | 10 ++++++++++ ld/testsuite/ld-i386/pr28870.s | 6 ++++++ 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 ld/testsuite/ld-i386/pr28870.d create mode 100644 ld/testsuite/ld-i386/pr28870.s diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c index 7ac2411fc80..d00dc45677b 100644 --- a/bfd/elfxx-x86.c +++ b/bfd/elfxx-x86.c @@ -1942,9 +1942,9 @@ _bfd_elf_x86_valid_reloc_p (asection *input_section, irel = *rel; /* Only allow relocations against absolute symbol, which can be - resolved as absolute value + addend. GOTPCREL relocations - are allowed since absolute value + addend is stored in the - GOT slot. */ + resolved as absolute value + addend. GOTPCREL and GOT32 + relocations are allowed since absolute value + addend is + stored in the GOT slot. */ if (bed->target_id == X86_64_ELF_DATA) { r_type &= ~R_X86_64_converted_reloc_bit; @@ -1965,7 +1965,9 @@ _bfd_elf_x86_valid_reloc_p (asection *input_section, else valid_p = (r_type == R_386_32 || r_type == R_386_16 - || r_type == R_386_8); + || r_type == R_386_8 + || r_type == R_386_GOT32 + || r_type == R_386_GOT32X); if (valid_p) *no_dynreloc_p = true; diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp index fe36b0fb533..82e14ab38d0 100644 --- a/ld/testsuite/ld-i386/i386.exp +++ b/ld/testsuite/ld-i386/i386.exp @@ -509,6 +509,7 @@ run_dump_test "pr27491-3" run_dump_test "pr27491-4" run_dump_test "dt-relr-1a" run_dump_test "dt-relr-1b" +run_dump_test "pr28870" if { !([istarget "i?86-*-linux*"] || [istarget "i?86-*-gnu*"] diff --git a/ld/testsuite/ld-i386/pr28870.d b/ld/testsuite/ld-i386/pr28870.d new file mode 100644 index 00000000000..8e9b9fb82eb --- /dev/null +++ b/ld/testsuite/ld-i386/pr28870.d @@ -0,0 +1,10 @@ +#as: --32 +#ld: --no-dynamic-linker -m elf_i386 -pie +#readelf: -s --wide + +#... +Symbol table '.symtab' contains [0-9]+ entries: + Num: Value Size Type Bind Vis Ndx Name +#... + +[a-f0-9]+: 00000002 0 NOTYPE LOCAL DEFAULT ABS foo +#pass diff --git a/ld/testsuite/ld-i386/pr28870.s b/ld/testsuite/ld-i386/pr28870.s new file mode 100644 index 00000000000..8e320470e2d --- /dev/null +++ b/ld/testsuite/ld-i386/pr28870.s @@ -0,0 +1,6 @@ + .text + .globl _start +_start: + addl foo@GOT(%ebx), %eax + cmpl $0, foo@GOT(%ebx) +foo = 2 -- 2.34.1