From: Florian Weimer <fweimer@redhat.com>
To: "Vivek Das Mohapatra" <vivek@collabora.com>
Cc: Mark Wielaard <mark@klomp.org>,
GNU gABI gnu-gabi <gnu-gabi@sourceware.org>
Subject: Re: ABI document
Date: Mon, 21 Sep 2020 15:03:57 +0200 [thread overview]
Message-ID: <87y2l31dtu.fsf@oldenburg2.str.redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.21.2009081308560.31454@noise.cbg.collabora.co.uk> ("Vivek =?utf-8?Q?Das=C2=A0Mohapatra=22's?= message of "Tue, 8 Sep 2020 13:09:47 +0100 (BST)")
* Vivek Das Mohapatra:
> + The GNU hash of a symbol is computed as follows:
> + - extract the NAME of the symbol
> + - examples: 'foo@version-info' becomes 'foo'; 'bar' remains 'bar'
> + - unsigned long h ← 5381
> + - for each unsigned character C in NAME, starting at position 0:
> + - h ← (h << 5) + h + C;
> + - HASH ← h & 0xffffffff // 32 bit value
Since the version is stored separately anyway, just say that the hash
covers the name only? Maybe write this?
h ← 31 * h + C
And just use uint32_t to express the truncation?
> +
> + Hash Table contents:
> +
> + bitmask-bits is a power of 2.
> + It is at least 32 (on 32 bit); at least 64 on 64 bit architectures.
> + There are other restrictions, see elflink.c in the binutils-gdb/bfd source.
> +
> + The bucket in which a symbol's hash entry is found is:
> +
> + gnu-hash( symbol-name ) % nbuckets
> +
> + The table is divided into 4 parts:
> + ----------------------------------------------------------------------------
> + Part 1 (metadata):
> +
> + - nbuckets : 4 byte native integer. Number of buckets
> + A bucket occupies 32 bits.
> +
> + - symoffset : 4 byte native integer.
> + Starting index of first "real" symbol in the ".dynsym"
> + section, See below.
> +
> + - bitmask-words: 4 byte native integer.
> + The number of ELFCLASS<SIZE> words in part 2 of the table.
> + On 64-bit architctures: bitmask-bits / 64
> + And on 32-bit ones : bitmask-bits / 32
> +
> + - bloom-shift : 4 byte native integer.
> + The shift-count used in the bloom filter.
> +
> + symoffset:
> + There are synthetic symbols - one for each section in the linker output.
> + symoffset gives the number of such synthetic symbols ( which cannot be
> + looked up via the GNU hash section described here ).
> +
> + NB: symbols that _can_ be looked up via the GNU hash must be stored in
> + the ".dynsym" section in ascending order of bucket.
> + That is the ordering is determined by:
> +
> + gnu-hash( symbol-name ) % nbuckets
> +
> + ----------------------------------------------------------------------------
> + Part 2 (the bloom filter bitmask):
> +
> + - bloom : ElfW(Addr)[ bitmask-words ]
> +
> + For each symbol [name] S the following is carried out:
> + - C ← __ELF_NATIVE_CLASS /* ie 32 on ELF32, 64 on ELF64 */
> + - H ← gnu-hash( S )
> + - BWORD ← (H / C) & (bitmask-words - 1)
> + - in bloom[ BWORD ] set:
> + - bit H & (C - 1)
> + - bit (H >> bloom-shift) & (C - 1)
Maybe say that the link editor does this?
The description looks correct.
> + For each symbol [name] S:
> +
> + - CHASH ← gnu-hash( S )
> + - BUCKET ← CHASH % nbuckets
> + - CINDEX ← position of the symbol _within_ its bucket
> + 0 for the first symbol, 1 for the second and so forth
I don't understand the “within its bucket” comment.
I think CINDEX increases sequentially among the symbols where CHASH %
nbuckets collides. Is that it?
> + - if this is the last symbol in the bucket:
> + - CHASH ← CHASH | 1 /* set the least bit */
> + - else
> + - CHASH ← CHASH & ~1 /* unset the least bit */
> + - BYTE-OFFSET ← (bucket[BUCKET] + CINDEX - symoffset) * 4
> + - CHAIN-ADDR ← ((char *)&bucket[nbuckets]) + BYTE-OFFSET
> + - *(ElfW(Word) *)(CHAIN-ADDR) ← CHASH
Kind of an odd way of writing this, but I think it's correct.
Thanks,
Florian
--
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill
next prev parent reply other threads:[~2020-09-21 13:04 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-29 11:47 Florian Weimer
2020-07-29 11:53 ` Mark Wielaard
2020-07-29 12:15 ` H.J. Lu
2020-07-29 12:22 ` Florian Weimer
2020-08-14 9:51 ` Vivek Das Mohapatra
2020-08-14 10:58 ` Mark Wielaard
2020-08-14 11:33 ` Vivek Das Mohapatra
2020-08-14 15:17 ` Mark Wielaard
2020-08-27 16:52 ` Vivek Das Mohapatra
2020-08-31 12:54 ` Florian Weimer
2020-09-02 17:29 ` Vivek Das Mohapatra
2020-09-08 12:09 ` Vivek Das Mohapatra
2020-09-16 13:57 ` Vivek Das Mohapatra
2020-09-21 13:03 ` Florian Weimer [this message]
2020-09-21 12:36 ` Florian Weimer
2020-11-27 15:40 ` Vivek Das Mohapatra
2020-11-30 17:36 ` Florian Weimer
2020-12-09 16:59 ` Vivek Das Mohapatra
2022-08-25 8:11 ` Florian Weimer
2022-08-25 15:38 ` Carlos O'Donell
2022-08-30 11:55 ` Vivek Dasmohapatra
2022-08-30 12:12 ` Florian Weimer
2022-08-30 15:17 ` Vivek Dasmohapatra
2020-07-29 12:56 ` Jose E. Marchesi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y2l31dtu.fsf@oldenburg2.str.redhat.com \
--to=fweimer@redhat.com \
--cc=gnu-gabi@sourceware.org \
--cc=mark@klomp.org \
--cc=vivek@collabora.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).