From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B7E403858D33 for ; Mon, 2 May 2022 07:21:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B7E403858D33 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-435-A7KvNTGZMTiIsHf96C-_2A-1; Mon, 02 May 2022 03:21:46 -0400 X-MC-Unique: A7KvNTGZMTiIsHf96C-_2A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E7474811E80; Mon, 2 May 2022 07:21:45 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 34319C27EA7; Mon, 2 May 2022 07:21:45 +0000 (UTC) From: Florian Weimer To: Fangrui Song Cc: Fangrui Song via Libc-alpha Subject: Re: [PATCH] elf: Remove fallback to the start of DT_STRTAB for dladdr References: <20220501215049.2143788-1-maskray@google.com> <87sfps8lt6.fsf@oldenburg.str.redhat.com> <20220502070415.kv62bjtdhhcyefjn@google.com> Date: Mon, 02 May 2022 09:21:43 +0200 In-Reply-To: <20220502070415.kv62bjtdhhcyefjn@google.com> (Fangrui Song's message of "Mon, 2 May 2022 00:04:15 -0700") Message-ID: <87k0b48kmw.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, 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: 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: Mon, 02 May 2022 07:21:50 -0000 * Fangrui Song: > On 2022-05-02, Florian Weimer wrote: >>* Fangrui Song via Libc-alpha: >> >>> When neither DT_HASH nor DT_GNU_HASH is present, the code scans >>> [DT_SYMTAB, DT_STRTAB). However, there is no guarantee that .dynstr >>> immediately follows .dynsym (e.g. lld typically places .gnu.version >>> after .dynsym). >> >>The code is compatible with lld because it always generates a hash >>table. Maybe it was added to support old binaries without a hash table. >>So we would have to check if such binaries exist from the early >>libc.so.6 days (or check if binutils every generated ELF binaries >>without a hash table). The glibc comment isn't clear if this was added >>because it was required at the time, or just because it seemed a good >>idea. >> >>I couldn't find any binaries with DT_SYMTAB, but without DT_HASH or >>DT_GNU_HASH in my collection, but doesn't mean that they don't exist. >> >>Thanks, >>Florian > > With a linker script .hash and .gnu.hash can be removed. > But such an object behaves as if it has no symbol: symbol search will fail. > It makes sense for dladdr to not return a symbol for it. > > % bmake > cc -pipe -g -fuse-ld=bfd -g -fpic -shared -Wl,--version-script=b.ver b.c -o b.so > cc -pipe -g -fuse-ld=bfd -g a.c -Wl,--no-as-needed -fno-pie -no-pie -Wl,-rpath=/tmp/d b.so -ldl -o a > % ./a > 42 > > % cat b.lds # GNU ld doesn't have this yet: https://sourceware.org/bugzilla/show_bug.cgi?id=26404 > OVERWRITE_SECTIONS { > /DISCARD/ : { *(.hash) *(.gnu.hash) } > } > % clang -fpic -fuse-ld=lld -shared b.c -Wl,b.lds -o b.so > % ./a > ./a: symbol lookup error: ./a: undefined symbol: var This looks like it might be an lld bug. DT_HASH is mandatory in the ELF specification. We ignore that requirement in the GNU ABI and use DT_GNU_HASH instead, even for static PIE binaries. Do you want to drop symbol tables from static PIE binaries? Thanks, Florian