From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id 86E4B3858405 for ; Fri, 22 Jul 2022 21:20:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 86E4B3858405 Received: by mail-pj1-x1036.google.com with SMTP id q41-20020a17090a1b2c00b001f2043c727aso5233105pjq.1 for ; Fri, 22 Jul 2022 14:20:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=IqZAvAGRy3akrDMaE7IZ8sjTU/9XDwwIxE+sKIaCi4M=; b=Xug/OPMylseYORqZPVcnXS1Wc1y2ff++DlDbzS4JkYy7oghtmzoe9Re6PRUk+Gwx7a xWx+ULHBG8wmsTDBc/ImpsmgdpOeUslZmcq+Rxa4NQqq8ND3dR5IHCcYtZMpktcKMbwS Tjr5l1CMuZ4Fm7gl8bqUN/QbcUarXnK55wqVBPOhemRayDVWomG9Iubm89TSFnHrg4m3 j10gKkWsWub1hSACUVxjxL8Uf1ksxGXpnTJu1T4JSluYiic8d6ieJ2CxUl26Qij0o7OC ZKcmMWCBzNAsil8wigko9ZT2lVBRN+BXIxp/i5ifktkYGJz7VrOGJlhtv5Ch/lQGolIy YbAA== X-Gm-Message-State: AJIora8QcmFl7L7J3JIyTfsLqGdnxt181G8Yo7dByBm1irjNwzFMdDFY 27TeEsBdfTXNaHagPLmUndjPdbjSHj1w75CHB6ftGjPO X-Google-Smtp-Source: AGRyM1vdfst1rkM0l8e4W41dFkb/KDH22pZCbmWmkn/QGjqleZloNsIjvGOW0p1K2ThbgDCz8HHkS08VumszcqtymTI= X-Received: by 2002:a17:90b:3ec3:b0:1f1:ff45:1d3b with SMTP id rm3-20020a17090b3ec300b001f1ff451d3bmr19178295pjb.101.1658524829107; Fri, 22 Jul 2022 14:20:29 -0700 (PDT) MIME-Version: 1.0 References: <20220721174047.1345337-1-hjl.tools@gmail.com> In-Reply-To: <20220721174047.1345337-1-hjl.tools@gmail.com> From: "H.J. Lu" Date: Fri, 22 Jul 2022 14:19:53 -0700 Message-ID: Subject: Re: [PATCH] i386: Don't allow GOTOFF relocation against IFUNC symbol for PIC To: Binutils Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3024.6 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 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.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Jul 2022 21:20:32 -0000 On Thu, Jul 21, 2022 at 10:40 AM H.J. Lu wrote: > > We can't use the PLT entry as the function address for PIC since the PIC > register may not be set up properly for indirect call. > > bfd/ > > PR ld/27998 > * elf32-i386.c (elf_i386_relocate_section): Don't allow GOTOFF > relocation against IFUNC symbol in PIC. > > ld/ > > PR ld/27998 > * testsuite/ld-i386/pr27998a.d: Replace -shared with -e bar. > * testsuite/ld-i386/pr27998b.d: Expect a linker error. > * testsuite/ld-ifunc/ifunc-2-i386-now.d: Updated. > * testsuite/ld-ifunc/ifunc-2-local-i386-now.d: Likewise. > * testsuite/ld-ifunc/ifunc-2-i386.s: Replace @GOTOFF with @GOT. > * testsuite/ld-ifunc/ifunc-2-local-i386.s: Likewise. > --- > bfd/elf32-i386.c | 5 +++++ > ld/testsuite/ld-i386/pr27998a.d | 2 +- > ld/testsuite/ld-i386/pr27998b.d | 6 +----- > ld/testsuite/ld-ifunc/ifunc-2-i386-now.d | 2 +- > ld/testsuite/ld-ifunc/ifunc-2-i386.s | 2 +- > ld/testsuite/ld-ifunc/ifunc-2-local-i386-now.d | 2 +- > ld/testsuite/ld-ifunc/ifunc-2-local-i386.s | 2 +- > 7 files changed, 11 insertions(+), 10 deletions(-) > > diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c > index cfb0085b245..52b1db44546 100644 > --- a/bfd/elf32-i386.c > +++ b/bfd/elf32-i386.c > @@ -2460,6 +2460,11 @@ elf_i386_relocate_section (bfd *output_bfd, > goto do_relocation; > > case R_386_GOTOFF: > + /* NB: We can't use the PLT entry as the function address > + for PIC since the PIC register may not be set up > + properly for indirect call. */ > + if (bfd_link_pic (info)) > + goto bad_ifunc_reloc; > relocation -= (gotplt->output_section->vma > + gotplt->output_offset); > goto do_relocation; > diff --git a/ld/testsuite/ld-i386/pr27998a.d b/ld/testsuite/ld-i386/pr27998a.d > index ca3c9205fa6..a8019730ec1 100644 > --- a/ld/testsuite/ld-i386/pr27998a.d > +++ b/ld/testsuite/ld-i386/pr27998a.d > @@ -1,5 +1,5 @@ > #as: --32 > -#ld: -shared -melf_i386 > +#ld: -e bar -melf_i386 > #readelf: -r --wide > > Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 1 entry: > diff --git a/ld/testsuite/ld-i386/pr27998b.d b/ld/testsuite/ld-i386/pr27998b.d > index ca3c9205fa6..8f81edbe8df 100644 > --- a/ld/testsuite/ld-i386/pr27998b.d > +++ b/ld/testsuite/ld-i386/pr27998b.d > @@ -1,7 +1,3 @@ > #as: --32 > #ld: -shared -melf_i386 > -#readelf: -r --wide > - > -Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 1 entry: > - Offset Info Type Sym. Value Symbol's Name > -[0-9a-f]+ +[0-9a-f]+ +R_386_IRELATIVE + > +#error: relocation R_386_GOTOFF against STT_GNU_IFUNC symbol `foo' isn't supported > diff --git a/ld/testsuite/ld-ifunc/ifunc-2-i386-now.d b/ld/testsuite/ld-ifunc/ifunc-2-i386-now.d > index a5c56b5a8e3..8d9e8dc988f 100644 > --- a/ld/testsuite/ld-ifunc/ifunc-2-i386-now.d > +++ b/ld/testsuite/ld-ifunc/ifunc-2-i386-now.d > @@ -31,6 +31,6 @@ Disassembly of section .text: > +[a-f0-9]+: 5b pop %ebx > +[a-f0-9]+: 81 c3 9e 10 00 00 add \$0x109e,%ebx > +[a-f0-9]+: e8 de ff ff ff call 100 <\*ABS\*@plt> > - +[a-f0-9]+: 8d 83 4c ef ff ff lea -0x10b4\(%ebx\),%eax > + +[a-f0-9]+: 8b 83 0c 00 00 00 mov 0xc\(%ebx\),%eax > +[a-f0-9]+: c3 ret > #pass > diff --git a/ld/testsuite/ld-ifunc/ifunc-2-i386.s b/ld/testsuite/ld-ifunc/ifunc-2-i386.s > index e84d6b7b5cc..1acf6847e0b 100644 > --- a/ld/testsuite/ld-ifunc/ifunc-2-i386.s > +++ b/ld/testsuite/ld-ifunc/ifunc-2-i386.s > @@ -16,6 +16,6 @@ bar: > popl %ebx > addl $_GLOBAL_OFFSET_TABLE_+[.-.L6], %ebx > call __GI_foo@PLT > - leal __GI_foo@GOTOFF(%ebx), %eax > + movl __GI_foo@GOT(%ebx), %eax > ret > .size bar, .-bar > diff --git a/ld/testsuite/ld-ifunc/ifunc-2-local-i386-now.d b/ld/testsuite/ld-ifunc/ifunc-2-local-i386-now.d > index ff494decbdd..9da37e51db7 100644 > --- a/ld/testsuite/ld-ifunc/ifunc-2-local-i386-now.d > +++ b/ld/testsuite/ld-ifunc/ifunc-2-local-i386-now.d > @@ -31,6 +31,6 @@ Disassembly of section .text: > +[a-f0-9]+: 5b pop %ebx > +[a-f0-9]+: 81 c3 9e 10 00 00 add \$0x109e,%ebx > +[a-f0-9]+: e8 de ff ff ff call f0 <\*ABS\*@plt> > - +[a-f0-9]+: 8d 83 4c ef ff ff lea -0x10b4\(%ebx\),%eax > + +[a-f0-9]+: 8b 83 0c 00 00 00 mov 0xc\(%ebx\),%eax > +[a-f0-9]+: c3 ret > #pass > diff --git a/ld/testsuite/ld-ifunc/ifunc-2-local-i386.s b/ld/testsuite/ld-ifunc/ifunc-2-local-i386.s > index a69e060ddc0..54e0e179551 100644 > --- a/ld/testsuite/ld-ifunc/ifunc-2-local-i386.s > +++ b/ld/testsuite/ld-ifunc/ifunc-2-local-i386.s > @@ -13,6 +13,6 @@ bar: > popl %ebx > addl $_GLOBAL_OFFSET_TABLE_+[.-.L6], %ebx > call __GI_foo@PLT > - leal __GI_foo@GOTOFF(%ebx), %eax > + movl __GI_foo@GOT(%ebx), %eax > ret > .size bar, .-bar > -- > 2.36.1 > I am backporting this to 2.38 and 2.39 branches. -- H.J.