From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id 156E43858D33 for ; Mon, 2 May 2022 07:04:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 156E43858D33 Received: by mail-pg1-x529.google.com with SMTP id j70so152058pge.1 for ; Mon, 02 May 2022 00:04:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=sBdcZhclE6z8Iz4SwRtQ9zRbhFi8oY6sqYw5/txW6Zc=; b=DJ84P0Vnvs+b1Z9y0Gu06kopwHw/p3Yue1y9fc7ZfQg8+cW/57PiGwZ3F3rdArrQrz cew3pIhEbTGRhZITwPzChcX4QBv1T+4a5pperVny/+RdNM+4Fk7FndcZtFqnV0anKKmX bQ1afOzih38Yxaryt9Xhuk4qTqtiS7cxIFoM4XGw7au7E+J+xOOtS+Rmvn9dwS9Rm6tv 2vHmv7FrgY2TGgevdwhx5LxyN8AEF1iV3nfYIjxyfLmsAZvXBwjCnZg9LJYxRMjut6Q1 Y3imV7+26sjq+/ZejYKAw6zI630DWZY/p0BND/c/BsVMaxIUiDTDHHMf1RdeFQ9OFZZg fBiw== X-Gm-Message-State: AOAM533euLhpIPOzfN9Tjj7JzklIRYB+ASMqABii/YMdqBdJ0wnKkjb5 UT0tYm8dexWOLLXI14LT1wc3IZQ9tergPA== X-Google-Smtp-Source: ABdhPJzsjQpvqNKPr2geoEC/w9yt4xtPf0V/G0FeAjJu/KnAjARf7i9PQTRwliTOIBKSg1Y8cp6uQA== X-Received: by 2002:a65:638d:0:b0:39d:74ad:ce0b with SMTP id h13-20020a65638d000000b0039d74adce0bmr8885252pgv.103.1651475058992; Mon, 02 May 2022 00:04:18 -0700 (PDT) Received: from google.com ([2620:15c:2ce:200:64b6:e3aa:b0d4:aff5]) by smtp.gmail.com with ESMTPSA id k4-20020a170902ba8400b0015e8d4eb230sm3888543pls.122.2022.05.02.00.04.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 00:04:18 -0700 (PDT) Date: Mon, 2 May 2022 00:04:15 -0700 From: Fangrui Song To: Florian Weimer Cc: Fangrui Song via Libc-alpha Subject: Re: [PATCH] elf: Remove fallback to the start of DT_STRTAB for dladdr Message-ID: <20220502070415.kv62bjtdhhcyefjn@google.com> References: <20220501215049.2143788-1-maskray@google.com> <87sfps8lt6.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <87sfps8lt6.fsf@oldenburg.str.redhat.com> X-Spam-Status: No, score=-20.0 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL 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:04:21 -0000 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 --- GNU ld doesn't seem to allow discarding both .gnu.hash and .hash: /DISCARD/ : { *(.hash) *(.gnu.hash) *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } /usr/bin/ld.bfd: could not find section .hash