From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS17314 8.43.84.0/22 X-Spam-Status: No, score=-4.2 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id D2DC91F8C6 for ; Mon, 9 Aug 2021 17:26:04 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F299D389853F for ; Mon, 9 Aug 2021 17:26:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F299D389853F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1628529964; bh=8NRFKv6I7kImXvMUzo5YI530/1hckJ1DzbXZAuxZu8k=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=IZKIKacViVRcMWWs/KGK8bTOKIKBQrrOAv2kY113niWsgy3uimAT/iTBv7/ERYHO9 zQeIbGD2Kv6OpiESfcN0Q+sTbqbOkEqvl7euc3Z/CTgU1Lt33PmCg+RSnvDDS7bN7D c2ITv2EticOtjyZMX1LS2cmbExNUcWIfguWEsvgk= Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by sourceware.org (Postfix) with ESMTPS id 2B405385E019 for ; Mon, 9 Aug 2021 17:25:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2B405385E019 Received: by mail-yb1-xb4a.google.com with SMTP id o126-20020a25d7840000b02905935dc071ddso7023248ybg.15 for ; Mon, 09 Aug 2021 10:25:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=8NRFKv6I7kImXvMUzo5YI530/1hckJ1DzbXZAuxZu8k=; b=FcM8Ies35i3o2XkaahBpuD7EoRZn78jzB0xei0PHK4tdgSzXQcSy62mSER/MBtJRvs sI0Mgbm7yhVMa8mM7VcxZBxIP9eimnf4pnBXtKWqrlq7WI3GzfeNm+NWeouDYQPk/fEz C8DYv+b3NoBNG61j31FoAmXZxOHAeiKQ3xoNGeC9jGPl5q3sjeDNPYBm0FVakS3rdoh2 PdE4uFepwNjE0bT0e/i2qic4ZY6u1aQpQprdKGnYCu1+06xfcke+bwKzSWwqoyWK+jW+ p/TJ8/7YEKrvEHxCiYXTWaiO6dAlewlN4oJ9djM40lyEt+UH3ivYPnyfMuB/Z74mZE9r ddAQ== X-Gm-Message-State: AOAM533Q1gMmV2JHonPvRUl44c7fWytLexdffCPAHQhU9ERw+tbUPdOF kaGp/LPzd7A1qfz8ssiUFA8gkpJJ8ZD+3Y755qMPE6b+JqNheqAA9oWCVAvRUzGtav9oJFhP6Vg hxyb0LXXX2xpNh7xrxQO5i3zYfd9v8k/OggajtfyDnqQWoxDXep4sh3BAm4IZAf6SfFFS X-Google-Smtp-Source: ABdhPJy1Vs7ye5bKF55MAXn2djI3GteaOr5b5YXpEssVgOUJ7Ljz1u8eMNSSmoIKK8r2Zsi9C0PEdNYxavjG X-Received: from maskray1.svl.corp.google.com ([2620:15c:2ce:200:f9:621e:68e0:4c6]) (user=maskray job=sendgmr) by 2002:a25:8082:: with SMTP id n2mr32523318ybk.79.1628529934725; Mon, 09 Aug 2021 10:25:34 -0700 (PDT) Date: Mon, 9 Aug 2021 10:25:30 -0700 Message-Id: <20210809172530.502327-1-maskray@google.com> Mime-Version: 1.0 Subject: [PATCH v2] aarch64: Make elf_machine_{load_address,dynamic} robust [BZ #28203] To: libc-alpha@sourceware.org, Adhemerval Zanella , Szabolcs Nagy Content-Type: text/plain; charset="UTF-8" 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: , From: Fangrui Song via Libc-alpha Reply-To: Fangrui Song Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" The AArch64 ABI is largely platform agnostic and does not specify _GLOBAL_OFFSET_TABLE_[0] ([1]). glibc ld.so turns out to be probably the only user of _GLOBAL_OFFSET_TABLE_[0] and GNU ld defines the value to the link-time address _DYNAMIC. [2] In 2012, __ehdr_start was implemented in GNU ld and gold in binutils 2.23. Using adrp+add / (-mcmodel=tiny) adr to access __ehdr_start/_DYNAMIC gives us a robust way to get the load address and the link-time address of _DYNAMIC. With https://sourceware.org/pipermail/libc-alpha/2021-August/129864.html, this patch, and disabling traditional TLSGD tests (neither Clang nor LLD's aarch64 port supports), LLD linked glibc has the same number of `make check` failures. [1]: From a psABI maintainer, https://bugs.llvm.org/show_bug.cgi?id=49672#c2 [2]: LLD's aarch64 port does not set _GLOBAL_OFFSET_TABLE_[0] to the link-time address _DYNAMIC. LLD is widely used on aarch64 Android and ChromeOS devices. Software just works without the need for _GLOBAL_OFFSET_TABLE_[0]. --- Changes from v1 * Use C instead of asm. -mcmodel=tiny adr is possible. * Adjust commit message --- sysdeps/aarch64/dl-machine.h | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/sysdeps/aarch64/dl-machine.h b/sysdeps/aarch64/dl-machine.h index d29d827ab3..3e10cb462f 100644 --- a/sysdeps/aarch64/dl-machine.h +++ b/sysdeps/aarch64/dl-machine.h @@ -37,28 +37,22 @@ elf_machine_matches_host (const ElfW(Ehdr) *ehdr) return ehdr->e_machine == EM_AARCH64; } -/* Return the link-time address of _DYNAMIC. Conveniently, this is the - first element of the GOT. */ -static inline ElfW(Addr) __attribute__ ((unused)) -elf_machine_dynamic (void) -{ - extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden; - return _GLOBAL_OFFSET_TABLE_[0]; -} - /* Return the run-time load address of the shared object. */ static inline ElfW(Addr) __attribute__ ((unused)) elf_machine_load_address (void) { - /* To figure out the load address we use the definition that for any symbol: - dynamic_addr(symbol) = static_addr(symbol) + load_addr + extern const ElfW(Ehdr) __ehdr_start attribute_hidden; + return (ElfW(Addr)) &__ehdr_start; +} - _DYNAMIC sysmbol is used here as its link-time address stored in - the special unrelocated first GOT entry. */ +/* Return the link-time address of _DYNAMIC. */ - extern ElfW(Dyn) _DYNAMIC[] attribute_hidden; - return (ElfW(Addr)) &_DYNAMIC - elf_machine_dynamic (); +static inline ElfW(Addr) __attribute__ ((unused)) +elf_machine_dynamic (void) +{ + extern ElfW(Dyn) _DYNAMIC[] attribute_hidden; + return (ElfW(Addr)) _DYNAMIC - elf_machine_load_address (); } /* Set up the loaded object described by L so its unrelocated PLT -- 2.32.0.605.g8dce9f2422-goog