From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by sourceware.org (Postfix) with ESMTPS id 85ADF385700D for ; Tue, 31 May 2022 13:48:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 85ADF385700D Received: by mail-pj1-x1034.google.com with SMTP id u12-20020a17090a1d4c00b001df78c7c209so2755735pju.1 for ; Tue, 31 May 2022 06:48:08 -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:cc; bh=JHHKh1tQW4/ZvVl4N37MO9ZiQlZvTUUZTD3kAEOdeoU=; b=PZfiJVyOmZmAJerxVGaqMwMQXq8+EA5GgDW6xGh/UkDFTVTgUUeEGzSryRN0760nxo OtRCuAOMPnj7iXvEGM1kHCPR42tcve2OYL8j9gbWif954NS/qoaGAvXIjKIaAKliodBX ZhjRBqmgm5odHBAuJwuG5pX8F/mOMP7CyU5GOR5cuXcEV5JK1BvQhAUcFkvjcWdCFTLk WrgG0AcNlCkUB3EmLtzRoJ6En6ihEowBrufurgJ4UHHfIndkceJOdvfWLuxl8XXLylnH vE5HZ4WYarFdbglA6KKuvaeIBGwMFQ3zqMXlMMOq5mPQuU6+iuUXyFM5y5R3HuvcWTW/ Ob3w== X-Gm-Message-State: AOAM531A8zvFyMLT4/OFcXkiUuzFKU9+LGUD0ltNy66TpJE2MyfyGgyt CiNCvm1FaHZ5pffboSLkz8eHfR1OImVBa9QiDSM= X-Google-Smtp-Source: ABdhPJy1EaFsWi/EoQeOyYdrT2i2izlLmibNSe4QbALHqnzcgFBNtL+T5iqd9JMX6Xs8vz67JGrxGXZwUkMYY8UU4b0= X-Received: by 2002:a17:90a:4897:b0:1c7:5fce:cbcd with SMTP id b23-20020a17090a489700b001c75fcecbcdmr28934557pjh.45.1654004887427; Tue, 31 May 2022 06:48:07 -0700 (PDT) MIME-Version: 1.0 References: <87mtf5wk0k.fsf@oldenburg.str.redhat.com> <8735gwhz9i.fsf@oldenburg.str.redhat.com> <878rqnf8nd.fsf@oldenburg.str.redhat.com> <20220531074930.sjzjdnkayy2ln2wa@google.com> In-Reply-To: <20220531074930.sjzjdnkayy2ln2wa@google.com> From: "H.J. Lu" Date: Tue, 31 May 2022 06:47:31 -0700 Message-ID: Subject: Re: [PATCH 2/3] Revert "[AArch64][BZ #17711] Fix extern protected data handling" To: Fangrui Song Cc: Florian Weimer , Szabolcs Nagy , GNU C Library , Wilco Dijkstra Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3019.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_INFOUSMEBIZ, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: , X-List-Received-Date: Tue, 31 May 2022 13:48:11 -0000 On Tue, May 31, 2022 at 12:49 AM Fangrui Song wrote: > > On 2022-05-30, H.J. Lu via Libc-alpha wrote: > >On Fri, May 27, 2022 at 5:43 AM Florian Weimer wrote: > >> > >> * Wilco Dijkstra: > >> > >> > Hi Florian, > >> > > >> > Sure, something basic like this shows the issues: > >> > > >> > int x; > >> > int f(void) { return ++x; } > >> > int main(void) { return f(); } > >> > > >> > compile with -O2 -fPIC -flto -shared: > >> > > >> > 00000000000004f0 : > >> > 4f0: b0000090 adrp x16, 11000 <__cxa_finalize@GLIBC_2.17> > >> > 4f4: f9400611 ldr x17, [x16, #8] > >> > 4f8: 91002210 add x16, x16, #0x8 > >> > 4fc: d61f0220 br x17 > >> > > >> > 0000000000000510
: > >> > 510: 17fffff8 b 4f0 > >> > > >> > 0000000000000600 : > >> > 600: 90000081 adrp x1, 10000 <__FRAME_END__+0xf8f8> > >> > 604: f947e821 ldr x1, [x1, #4048] > >> > 608: b9400020 ldr w0, [x1] > >> > 60c: 11000400 add w0, w0, #0x1 > >> > 610: b9000020 str w0, [x1] > >> > 614: d65f03c0 ret > >> > >> Can you link with a version script? > >> > >> { local: *; global: main; }; > >> > >> Exporting symbols inhibits some optimizations even if interposition is > >> assumed not to happen because the behavior of public entry points needs > >> to be preserved. With a version script, the set of entry points can be > >> greatly reduced, enabling further optimizations. > >> > >> Thanks, > >> Florian > >> > > > >Should -fno-semantic-interposition imply -fvisibility=protected > >-mno-direct-extern-access? > > Unfortunately, no. -fvisibility=protected imposes stricter requirement > than -fno-semantic-interposition. See > https://maskray.me/blog/2021-01-09-copy-relocations-canonical-plt-entries-and-protected#protected-function-symbols-and-canonical-plt-entries > > __attribute__((visibility("protected"))) void *foo() { > return (void *)foo; > } > > GNU ld does not support this on several architectures, including the common x86-32/x86-64/aarch64. > > % gcc -m32 -fpic -shared -fuse-ld=bfd b.c > /usr/bin/ld.bfd: /tmp/cc3Ay0Gh.o: relocation R_X86_64_PC32 against protected symbol `foo' can not be used when making a shared object > /usr/bin/ld.bfd: final link failed: bad value > collect2: error: ld returned 1 exit status Add -mno-direct-extern-access with binutils 2.39 or 2.38 branch works. > % aarch64-linux-gnu-gcc -fpic -shared -fuse-ld=bfd b.c > /usr/lib/gcc-cross/aarch64-linux-gnu/11/../../../../aarch64-linux-gnu/bin/ld.bfd: /tmp/ccJf24eh.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `foo' which may bind externally can not be used when making a shared object; recompile with -fPIC > /tmp/ccJf24eh.o: in function `foo': > b.c:(.text+0x0): dangerous relocation: unsupported relocation > collect2: error: ld returned 1 exit status > > -- H.J.