From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by server2.sourceware.org (Postfix) with ESMTPS id 1C795393742D for ; Mon, 9 Mar 2020 04:59:09 +0000 (GMT) Received: by mail-pf1-x443.google.com with SMTP id g21so4260003pfb.5 for ; Sun, 08 Mar 2020 21:59:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:references:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Rvt0AXiax7yA5rU/qHUaKWmBT2V7Nc5kRyBb/pTJOF8=; b=GockZNKSpRhDM/ADACQCGvX8R1ooREHb4Jy20Dv53uIkWjmXCbHj04uB4T2XpwoRmJ snl+hsvyOVOgzMcxQ9N1g5bQQ1xGv9Pkc1c51jJ2vxcdPHwvjS+WEtEnXOjJncmvldzm pmc03RErl0QOygJrZdXhXNG84QNStaJnFkFW7W6ajBPi75r+YNBvNAuP+uyoja/XPyk+ HUCFe+45OLrd3WVdD0I15KO5gLVDzB1MwzECXiR8uzRyYvaUYz7FGkCG5M9kGflnZkfF eTc/ygCNitPODhOlC2RGOuvWSNTL1QkdjIrWYuE5f24hTZiEslBgaDJO4Dx08+6lD+xb LaPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:references:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=Rvt0AXiax7yA5rU/qHUaKWmBT2V7Nc5kRyBb/pTJOF8=; b=OqQ2Q1LdzDvP9IJi9kmy3a1amKIMl2VYpIgLIqqT0WVp2yuGolMGtEdYtWiZtEA4Ns sAA7g4IdO9Yn9L+BMtqr2W6kI9kIYcsNSYeRmY5pEfyiXTuw697opFbno+qQs+vTU8W3 QzEpFsdbcXb/Wj3auW1b9AbKzuxuGi7I+xM14bbbBNdER8EaA708Oa4oA4PBPKjjM0qY 1d7MOONTgBxjuix1CcqgSZSxg6uixfk3HN1rTJxxICjxS2dff5GclyxJl3mePsaEjhnw mXk54/Kt7GLIcvzqwE9wDBa0u2nnvAawqBQ6oeGF2q8a41jrloHkf8P2l9t3rA5p4al7 zgSw== X-Gm-Message-State: ANhLgQ3Wu8QUAZmbtRsXaT7472cYH2lL+y27r+ITRimly4q/IJldltzr lGgopuQHqSAd9+EJ6+7PYkpJ2GNt X-Google-Smtp-Source: ADFU+vuy6n8JBgXP7haXye4qT4MKnNIC/8zuZSfp0GwgZqAj+OeLWBsGV4P/i19p4V8WpsNnqe489g== X-Received: by 2002:a63:7a1a:: with SMTP id v26mr14358735pgc.152.1583729947971; Sun, 08 Mar 2020 21:59:07 -0700 (PDT) Received: from [10.0.2.1] (61-245-154-180.3df59a.adl.nbn.aussiebb.net. [61.245.154.180]) by smtp.googlemail.com with ESMTPSA id x14sm35040410pfr.23.2020.03.08.21.59.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Mar 2020 21:59:07 -0700 (PDT) From: Kaylee Blake Subject: RFC: [PATCH] ELF: Don't require section header on ELF objects To: Binutils References: <20200308175947.GA911529@gmail.com> <20200308233553.GG5384@bubble.grove.modra.org> <20200309000543.GJ5384@bubble.grove.modra.org> <0ad58560-3dd4-badd-5661-9f74905a7df3@gmail.com> <20200309022309.GK5384@bubble.grove.modra.org> Openpgp: preference=signencrypt Autocrypt: addr=klkblake@gmail.com; prefer-encrypt=mutual; keydata= xsBNBFEjQLEBCADjjSJEqGgOWM+dK6wvOi5B/i1LFM00hy9x1bZZCj34Z7/6H60KhI00yRaj bJzPzmlAO402Ac69NZMXV+mmFFBAabIg70R0VyJKPxX7QyZ4GM9K9w2+LZM+9OgKhOzoypMa S0O93f4EdJ9R7GbsbnWf4SOhv7tKAnJr3jZwp55YkQDnZBHvLw4r8vHykTd6E198CG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RAI386DSY0JozmEB/9k0s1wDQagXUMw 1HAX0R86QtrIChHINkaD1xhquuNpCD1vkIqbZSfw50jR+unBpqNOTcJcuBsi6dWI6maHw1Xd 27T6Jgm/5C2sgUD6dYFFATGlotID2jNRhYe7PfzL38RDIkx9qi5o7b3/zh20Tm+CLZm1bX7T X7D2TANhpl1S2IusNJUBk2ZMXft3ADeIThYd4xEWiT27zYdV1dBOQLiS4qYW1v+EojnnmoIP xoHvXdSGfLyJTTwqLw1yXxL9yMVfNEl/AGPhMHtwbtWTMofGbLCTrHp03pqCTNaF2VHE0HuO eUz1vhRCYch06svzICIRcrn7NyJvcGhil4f5SF/dwsB8BBgBAgAmAhsMFiEEo7CtRavdB/21 tGFZCN/Og0mNCaMFAl4qYhwFCQ7oVOsACgkQCN/Og0mNCaMiZgf+IZZV5fg1mNscH90Py/k2 I5zznzXqdnCd5DmocX3t9Z26/mcTI0hQhiY8UZFkDxI3E0LFu8hDaRB+ioXNidVNdWZAhpr2 zDMjjwVmlx/Jt3+MI/RygsidIRuYYGy94RLvYTQh6qfuHy/5GDIwgsq+S0MfjdcPCO5NLpPH 8pYowlZiehA0QT5hwNzFR1S2YvxHr+nN99jxhOnQZ2TUt5+mQfXwfCQVHoSiJKrwU6z8Q85o ClHHtbUpOY+W6S2I9lRgeaF/fiDo6nZeKRaF5enwxLHuz6tXkdv04vDx5lJevqjtvUUCglQ1 EdpFPEpbpgoe5SmlCrB+cO0ATaAAA06SxQ== Message-ID: <1e07d894-db32-1a54-425b-6f83e228017c@gmail.com> Date: Mon, 9 Mar 2020 15:29:04 +1030 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HK_RANDOM_ENVFROM, HK_RANDOM_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Mon, 09 Mar 2020 04:59:10 -0000 On 9/3/20 2:44 pm, H.J. Lu wrote: > On Sun, Mar 8, 2020 at 7:35 PM H.J. Lu wrote: >> >> On Sun, Mar 8, 2020 at 7:23 PM Alan Modra wrote: >>> >>> On Mon, Mar 09, 2020 at 12:29:48PM +1030, Kaylee Blake wrote: >>>> On 9/3/20 12:06 pm, H.J. Lu wrote: >>>>> On Sun, Mar 8, 2020 at 5:05 PM Alan Modra wrote: >>>>>> Well we certainly don't do such sorting. For example, from a freshly >>>>>> build ld/ld-new --enable-targets=all >>>>>> >>>>>> 148: 0000000000f08380 4 OBJECT GLOBAL DEFAULT 25 opterr@GLIBC_2.2.5 (3) >>>>>> 149: 0000000000402f80 0 FUNC GLOBAL DEFAULT UND calloc@GLIBC_2.2.5 (3) >>>>>> 150: 0000000000881536 35 FUNC GLOBAL DEFAULT 13 _obstack_allocated_p >>>>>> >>>>> >>>>> I will make 2 changes: >>>>> >>>>> 1. Update -z nosectionheader to guarantee that the last entry in >>>>> dynamic symbol table >>>>> is defined. >>>>> 2. Update --remove-section-header to issue an error if the last entry >>>>> in dynamic symbol >>>>> table is undefined. >>>>> >>>> >>>> With some testing, it seems like ld will emit an ordered symbol table >>>> iff it's using the DT_GNU_HASH hash table style >>> >>> It doesn't. The snippet of .dynsym I posted was from a binary with >>> DT_GNU_HASH. elflink.c:_bfd_elf_link_renumber_dynsyms should convince >>> you that any ordering seen is by chance. >>> >>>> , and my understanding is >>>> that DT_GNU_HASH in fact requires this behaviour. >>> >>> Apparently not. ;-) >>> >>>> So in that case, we >>>> don't need to do an additional check, because we only need the ordering >>>> if we are looking up through DT_GNU_HASH instead of DT_HASH. >>>> >>>> -- >>>> Kaylee Blake >>>> C is the worst language, except for all the others. >>> >> >> x86 backend does: >> >> if (!local_undefweak >> && !h->def_regular >> && (h->plt.offset != (bfd_vma) -1 >> || eh->plt_got.offset != (bfd_vma) -1)) >> { >> /* Mark the symbol as undefined, rather than as defined in >> the .plt section. Leave the value if there were any >> relocations where pointer equality matters (this is a clue >> for the dynamic linker, to make function pointer >> comparisons work between an application and shared >> library), otherwise set it to zero. If a function is only >> called from a binary, there is no need to slow down >> shared libraries because of that. */ >> sym->st_shndx = SHN_UNDEF; >> if (!h->pointer_equality_needed) >> sym->st_value = 0; >> } >> >> Entries in DT_GNU_HASH were originally defined. A backend >> may change some entries to undefined. I think my patch is OK. >> > > [hjl@gnu-cfl-2 pr25617]$ cat y.s > .data > bar: > .dc.a foo > [hjl@gnu-cfl-2 pr25617]$ gcc -c y.s > [hjl@gnu-cfl-2 pr25617]$ ./ld -shared y.o --hash-style=sysv > [hjl@gnu-cfl-2 pr25617]$ readelf -D -s a.out > > Symbol table for image: > Num Buc: Value Size Type Bind Vis Ndx Name > 1 0: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND foo > [hjl@gnu-cfl-2 pr25617]$ ./ld -shared y.o --hash-style=gnu > [hjl@gnu-cfl-2 pr25617]$ readelf -D -s a.out > [hjl@gnu-cfl-2 pr25617]$ > > I will update my patch to not to generate such binary without section > header. > A possible alternative if we have DT_GNU_HASH is to scan through the relocation list. Every symbol we care about for linking must either be something this library is providing (in which case it's in the range provided by DT_GNU_HASH), or something it needs (in which there will be a relocation referencing it). So if there is no DT_HASH, we can take the max of the highest DT_GNU_HASH symbol and the highest symbol referenced by a relocation entry. Theoretically there could be a symbol which is undefined but never referenced in a relocation, but the dynamic linker doesn't have any information we don't, so it can't affect anything if we don't have a way to get it. -- Kaylee Blake C is the worst language, except for all the others.