* [musl] [PATCH v3] vdso: add support for GNU hash tables
@ 2025-08-22 22:54 tombo
2025-08-24 2:26 ` Rich Felker
0 siblings, 1 reply; 6+ messages in thread
From: tombo @ 2025-08-22 22:54 UTC (permalink / raw)
To: musl; +Cc: tombo
Hi Rich, thanks for the review. Hopefully this version addresses all the points.
---
src/internal/vdso.c | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/src/internal/vdso.c b/src/internal/vdso.c
index d46d3228..2b6e1ae2 100644
--- a/src/internal/vdso.c
+++ b/src/internal/vdso.c
@@ -40,6 +40,24 @@ static int checkver(Verdef *def, int vsym, const char *vername, char *strings)
#define OK_TYPES (1<<STT_NOTYPE | 1<<STT_OBJECT | 1<<STT_FUNC | 1<<STT_COMMON)
#define OK_BINDS (1<<STB_GLOBAL | 1<<STB_WEAK | 1<<STB_GNU_UNIQUE)
+static size_t count_syms_gnu(uint32_t *gh)
+{
+ size_t nsym, i;
+ uint32_t *buckets = gh + 4 + (gh[2]*sizeof(size_t)/4);
+ uint32_t *hashval;
+ for (i = nsym = 0; i < gh[0]; i++) {
+ if (buckets[i] > nsym)
+ nsym = buckets[i];
+ }
+ if (nsym) {
+ hashval = buckets + gh[0] + (nsym - gh[1]);
+ do nsym++;
+ while (!(*hashval++ & 1));
+ }
+ return nsym;
+}
+
+
void *__vdsosym(const char *vername, const char *name)
{
size_t i;
@@ -60,6 +78,7 @@ void *__vdsosym(const char *vername, const char *name)
char *strings = 0;
Sym *syms = 0;
Elf_Symndx *hashtab = 0;
+ uint32_t *ghashtab = 0;
uint16_t *versym = 0;
Verdef *verdef = 0;
@@ -69,15 +88,20 @@ void *__vdsosym(const char *vername, const char *name)
case DT_STRTAB: strings = p; break;
case DT_SYMTAB: syms = p; break;
case DT_HASH: hashtab = p; break;
+ case DT_GNU_HASH: ghashtab = p; break;
case DT_VERSYM: versym = p; break;
case DT_VERDEF: verdef = p; break;
}
}
- if (!strings || !syms || !hashtab) return 0;
+ if (!strings || !syms) return 0;
if (!verdef) versym = 0;
+ size_t nsym = 0;
+
+ if (hashtab) nsym = hashtab[1];
+ else if (ghashtab) nsym = count_syms_gnu(ghashtab);
- for (i=0; i<hashtab[1]; i++) {
+ for (i=0; i<nsym; i++) {
if (!(1<<(syms[i].st_info&0xf) & OK_TYPES)) continue;
if (!(1<<(syms[i].st_info>>4) & OK_BINDS)) continue;
if (!syms[i].st_shndx) continue;
--
2.46.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [musl] [PATCH v3] vdso: add support for GNU hash tables
2025-08-22 22:54 [musl] [PATCH v3] vdso: add support for GNU hash tables tombo
@ 2025-08-24 2:26 ` Rich Felker
2025-08-24 9:25 ` Tomáš Hulata
0 siblings, 1 reply; 6+ messages in thread
From: Rich Felker @ 2025-08-24 2:26 UTC (permalink / raw)
To: tombo; +Cc: musl
On Sat, Aug 23, 2025 at 12:54:04AM +0200, tombo wrote:
> Hi Rich, thanks for the review. Hopefully this version addresses all the points.
>
> ---
> src/internal/vdso.c | 28 ++++++++++++++++++++++++++--
> 1 file changed, 26 insertions(+), 2 deletions(-)
>
> diff --git a/src/internal/vdso.c b/src/internal/vdso.c
> index d46d3228..2b6e1ae2 100644
> --- a/src/internal/vdso.c
> +++ b/src/internal/vdso.c
> @@ -40,6 +40,24 @@ static int checkver(Verdef *def, int vsym, const char *vername, char *strings)
> #define OK_TYPES (1<<STT_NOTYPE | 1<<STT_OBJECT | 1<<STT_FUNC | 1<<STT_COMMON)
> #define OK_BINDS (1<<STB_GLOBAL | 1<<STB_WEAK | 1<<STB_GNU_UNIQUE)
>
> +static size_t count_syms_gnu(uint32_t *gh)
> +{
> + size_t nsym, i;
> + uint32_t *buckets = gh + 4 + (gh[2]*sizeof(size_t)/4);
> + uint32_t *hashval;
> + for (i = nsym = 0; i < gh[0]; i++) {
> + if (buckets[i] > nsym)
> + nsym = buckets[i];
> + }
> + if (nsym) {
> + hashval = buckets + gh[0] + (nsym - gh[1]);
> + do nsym++;
> + while (!(*hashval++ & 1));
> + }
> + return nsym;
> +}
> +
> +
> void *__vdsosym(const char *vername, const char *name)
> {
> size_t i;
> @@ -60,6 +78,7 @@ void *__vdsosym(const char *vername, const char *name)
> char *strings = 0;
> Sym *syms = 0;
> Elf_Symndx *hashtab = 0;
> + uint32_t *ghashtab = 0;
> uint16_t *versym = 0;
> Verdef *verdef = 0;
>
> @@ -69,15 +88,20 @@ void *__vdsosym(const char *vername, const char *name)
> case DT_STRTAB: strings = p; break;
> case DT_SYMTAB: syms = p; break;
> case DT_HASH: hashtab = p; break;
> + case DT_GNU_HASH: ghashtab = p; break;
> case DT_VERSYM: versym = p; break;
> case DT_VERDEF: verdef = p; break;
> }
> }
>
> - if (!strings || !syms || !hashtab) return 0;
> + if (!strings || !syms) return 0;
> if (!verdef) versym = 0;
> + size_t nsym = 0;
> +
> + if (hashtab) nsym = hashtab[1];
> + else if (ghashtab) nsym = count_syms_gnu(ghashtab);
>
> - for (i=0; i<hashtab[1]; i++) {
> + for (i=0; i<nsym; i++) {
> if (!(1<<(syms[i].st_info&0xf) & OK_TYPES)) continue;
> if (!(1<<(syms[i].st_info>>4) & OK_BINDS)) continue;
> if (!syms[i].st_shndx) continue;
> --
> 2.46.0
Thanks! I don't see anything obviously wrong with this. I'll take a
more detailed look over it soon. Are you hoping to get it included in
this release cycle?
Rich
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [musl] [PATCH v3] vdso: add support for GNU hash tables
2025-08-24 2:26 ` Rich Felker
@ 2025-08-24 9:25 ` Tomáš Hulata
2025-11-06 21:59 ` Tomáš Hulata
0 siblings, 1 reply; 6+ messages in thread
From: Tomáš Hulata @ 2025-08-24 9:25 UTC (permalink / raw)
To: musl; +Cc: Rich Felker
It would be great to get it included, but it's up to you. I'm going to
use a fork till it is not released.
Thanks
Best Regards
Tomáš Hulata
[ SysArt / Pixel Federation ]
On Sun, Aug 24, 2025 at 4:26 AM Rich Felker <dalias@libc.org> wrote:
>
> On Sat, Aug 23, 2025 at 12:54:04AM +0200, tombo wrote:
> > Hi Rich, thanks for the review. Hopefully this version addresses all the points.
> >
> > ---
> > src/internal/vdso.c | 28 ++++++++++++++++++++++++++--
> > 1 file changed, 26 insertions(+), 2 deletions(-)
> >
> > diff --git a/src/internal/vdso.c b/src/internal/vdso.c
> > index d46d3228..2b6e1ae2 100644
> > --- a/src/internal/vdso.c
> > +++ b/src/internal/vdso.c
> > @@ -40,6 +40,24 @@ static int checkver(Verdef *def, int vsym, const char *vername, char *strings)
> > #define OK_TYPES (1<<STT_NOTYPE | 1<<STT_OBJECT | 1<<STT_FUNC | 1<<STT_COMMON)
> > #define OK_BINDS (1<<STB_GLOBAL | 1<<STB_WEAK | 1<<STB_GNU_UNIQUE)
> >
> > +static size_t count_syms_gnu(uint32_t *gh)
> > +{
> > + size_t nsym, i;
> > + uint32_t *buckets = gh + 4 + (gh[2]*sizeof(size_t)/4);
> > + uint32_t *hashval;
> > + for (i = nsym = 0; i < gh[0]; i++) {
> > + if (buckets[i] > nsym)
> > + nsym = buckets[i];
> > + }
> > + if (nsym) {
> > + hashval = buckets + gh[0] + (nsym - gh[1]);
> > + do nsym++;
> > + while (!(*hashval++ & 1));
> > + }
> > + return nsym;
> > +}
> > +
> > +
> > void *__vdsosym(const char *vername, const char *name)
> > {
> > size_t i;
> > @@ -60,6 +78,7 @@ void *__vdsosym(const char *vername, const char *name)
> > char *strings = 0;
> > Sym *syms = 0;
> > Elf_Symndx *hashtab = 0;
> > + uint32_t *ghashtab = 0;
> > uint16_t *versym = 0;
> > Verdef *verdef = 0;
> >
> > @@ -69,15 +88,20 @@ void *__vdsosym(const char *vername, const char *name)
> > case DT_STRTAB: strings = p; break;
> > case DT_SYMTAB: syms = p; break;
> > case DT_HASH: hashtab = p; break;
> > + case DT_GNU_HASH: ghashtab = p; break;
> > case DT_VERSYM: versym = p; break;
> > case DT_VERDEF: verdef = p; break;
> > }
> > }
> >
> > - if (!strings || !syms || !hashtab) return 0;
> > + if (!strings || !syms) return 0;
> > if (!verdef) versym = 0;
> > + size_t nsym = 0;
> > +
> > + if (hashtab) nsym = hashtab[1];
> > + else if (ghashtab) nsym = count_syms_gnu(ghashtab);
> >
> > - for (i=0; i<hashtab[1]; i++) {
> > + for (i=0; i<nsym; i++) {
> > if (!(1<<(syms[i].st_info&0xf) & OK_TYPES)) continue;
> > if (!(1<<(syms[i].st_info>>4) & OK_BINDS)) continue;
> > if (!syms[i].st_shndx) continue;
> > --
> > 2.46.0
>
> Thanks! I don't see anything obviously wrong with this. I'll take a
> more detailed look over it soon. Are you hoping to get it included in
> this release cycle?
>
> Rich
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [musl] [PATCH v3] vdso: add support for GNU hash tables
2025-08-24 9:25 ` Tomáš Hulata
@ 2025-11-06 21:59 ` Tomáš Hulata
2025-11-12 17:17 ` Rich Felker
0 siblings, 1 reply; 6+ messages in thread
From: Tomáš Hulata @ 2025-11-06 21:59 UTC (permalink / raw)
To: musl; +Cc: Rich Felker
Hi Rich,
just reminding with this simple patch.
It would be great to get it merged.
Thanks
Best Regards
Tomáš Hulata
[ SysArt / Pixel Federation ]
On Sun, Aug 24, 2025 at 11:25 AM Tomáš Hulata <hulata@sysart.tech> wrote:
>
> It would be great to get it included, but it's up to you. I'm going to
> use a fork till it is not released.
> Thanks
>
> Best Regards
> Tomáš Hulata
> [ SysArt / Pixel Federation ]
>
> On Sun, Aug 24, 2025 at 4:26 AM Rich Felker <dalias@libc.org> wrote:
> >
> > On Sat, Aug 23, 2025 at 12:54:04AM +0200, tombo wrote:
> > > Hi Rich, thanks for the review. Hopefully this version addresses all the points.
> > >
> > > ---
> > > src/internal/vdso.c | 28 ++++++++++++++++++++++++++--
> > > 1 file changed, 26 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/src/internal/vdso.c b/src/internal/vdso.c
> > > index d46d3228..2b6e1ae2 100644
> > > --- a/src/internal/vdso.c
> > > +++ b/src/internal/vdso.c
> > > @@ -40,6 +40,24 @@ static int checkver(Verdef *def, int vsym, const char *vername, char *strings)
> > > #define OK_TYPES (1<<STT_NOTYPE | 1<<STT_OBJECT | 1<<STT_FUNC | 1<<STT_COMMON)
> > > #define OK_BINDS (1<<STB_GLOBAL | 1<<STB_WEAK | 1<<STB_GNU_UNIQUE)
> > >
> > > +static size_t count_syms_gnu(uint32_t *gh)
> > > +{
> > > + size_t nsym, i;
> > > + uint32_t *buckets = gh + 4 + (gh[2]*sizeof(size_t)/4);
> > > + uint32_t *hashval;
> > > + for (i = nsym = 0; i < gh[0]; i++) {
> > > + if (buckets[i] > nsym)
> > > + nsym = buckets[i];
> > > + }
> > > + if (nsym) {
> > > + hashval = buckets + gh[0] + (nsym - gh[1]);
> > > + do nsym++;
> > > + while (!(*hashval++ & 1));
> > > + }
> > > + return nsym;
> > > +}
> > > +
> > > +
> > > void *__vdsosym(const char *vername, const char *name)
> > > {
> > > size_t i;
> > > @@ -60,6 +78,7 @@ void *__vdsosym(const char *vername, const char *name)
> > > char *strings = 0;
> > > Sym *syms = 0;
> > > Elf_Symndx *hashtab = 0;
> > > + uint32_t *ghashtab = 0;
> > > uint16_t *versym = 0;
> > > Verdef *verdef = 0;
> > >
> > > @@ -69,15 +88,20 @@ void *__vdsosym(const char *vername, const char *name)
> > > case DT_STRTAB: strings = p; break;
> > > case DT_SYMTAB: syms = p; break;
> > > case DT_HASH: hashtab = p; break;
> > > + case DT_GNU_HASH: ghashtab = p; break;
> > > case DT_VERSYM: versym = p; break;
> > > case DT_VERDEF: verdef = p; break;
> > > }
> > > }
> > >
> > > - if (!strings || !syms || !hashtab) return 0;
> > > + if (!strings || !syms) return 0;
> > > if (!verdef) versym = 0;
> > > + size_t nsym = 0;
> > > +
> > > + if (hashtab) nsym = hashtab[1];
> > > + else if (ghashtab) nsym = count_syms_gnu(ghashtab);
> > >
> > > - for (i=0; i<hashtab[1]; i++) {
> > > + for (i=0; i<nsym; i++) {
> > > if (!(1<<(syms[i].st_info&0xf) & OK_TYPES)) continue;
> > > if (!(1<<(syms[i].st_info>>4) & OK_BINDS)) continue;
> > > if (!syms[i].st_shndx) continue;
> > > --
> > > 2.46.0
> >
> > Thanks! I don't see anything obviously wrong with this. I'll take a
> > more detailed look over it soon. Are you hoping to get it included in
> > this release cycle?
> >
> > Rich
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [musl] [PATCH v3] vdso: add support for GNU hash tables
2025-11-06 21:59 ` Tomáš Hulata
@ 2025-11-12 17:17 ` Rich Felker
2025-11-12 19:45 ` Markus Wichmann
0 siblings, 1 reply; 6+ messages in thread
From: Rich Felker @ 2025-11-12 17:17 UTC (permalink / raw)
To: Tomáš Hulata; +Cc: musl
On Thu, Nov 06, 2025 at 10:59:45PM +0100, Tomáš Hulata wrote:
> Hi Rich,
> just reminding with this simple patch.
> It would be great to get it merged.
> Thanks
Thanks for the ping! I was probably initially planning to hold off on
this til a new release cycle, but I don't see any way it could break.
It surely won't break on any kernel that has the standard ELF hash
table available in the vdso like it should. If nobody has objections
(I'd appreciate a second set of eyes from anyone willing to read it) I
think this is ok to go ahead and apply.
Rich
> On Sun, Aug 24, 2025 at 11:25 AM Tomáš Hulata <hulata@sysart.tech> wrote:
> >
> > It would be great to get it included, but it's up to you. I'm going to
> > use a fork till it is not released.
> > Thanks
> >
> > Best Regards
> > Tomáš Hulata
> > [ SysArt / Pixel Federation ]
> >
> > On Sun, Aug 24, 2025 at 4:26 AM Rich Felker <dalias@libc.org> wrote:
> > >
> > > On Sat, Aug 23, 2025 at 12:54:04AM +0200, tombo wrote:
> > > > Hi Rich, thanks for the review. Hopefully this version addresses all the points.
> > > >
> > > > ---
> > > > src/internal/vdso.c | 28 ++++++++++++++++++++++++++--
> > > > 1 file changed, 26 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/src/internal/vdso.c b/src/internal/vdso.c
> > > > index d46d3228..2b6e1ae2 100644
> > > > --- a/src/internal/vdso.c
> > > > +++ b/src/internal/vdso.c
> > > > @@ -40,6 +40,24 @@ static int checkver(Verdef *def, int vsym, const char *vername, char *strings)
> > > > #define OK_TYPES (1<<STT_NOTYPE | 1<<STT_OBJECT | 1<<STT_FUNC | 1<<STT_COMMON)
> > > > #define OK_BINDS (1<<STB_GLOBAL | 1<<STB_WEAK | 1<<STB_GNU_UNIQUE)
> > > >
> > > > +static size_t count_syms_gnu(uint32_t *gh)
> > > > +{
> > > > + size_t nsym, i;
> > > > + uint32_t *buckets = gh + 4 + (gh[2]*sizeof(size_t)/4);
> > > > + uint32_t *hashval;
> > > > + for (i = nsym = 0; i < gh[0]; i++) {
> > > > + if (buckets[i] > nsym)
> > > > + nsym = buckets[i];
> > > > + }
> > > > + if (nsym) {
> > > > + hashval = buckets + gh[0] + (nsym - gh[1]);
> > > > + do nsym++;
> > > > + while (!(*hashval++ & 1));
> > > > + }
> > > > + return nsym;
> > > > +}
> > > > +
> > > > +
> > > > void *__vdsosym(const char *vername, const char *name)
> > > > {
> > > > size_t i;
> > > > @@ -60,6 +78,7 @@ void *__vdsosym(const char *vername, const char *name)
> > > > char *strings = 0;
> > > > Sym *syms = 0;
> > > > Elf_Symndx *hashtab = 0;
> > > > + uint32_t *ghashtab = 0;
> > > > uint16_t *versym = 0;
> > > > Verdef *verdef = 0;
> > > >
> > > > @@ -69,15 +88,20 @@ void *__vdsosym(const char *vername, const char *name)
> > > > case DT_STRTAB: strings = p; break;
> > > > case DT_SYMTAB: syms = p; break;
> > > > case DT_HASH: hashtab = p; break;
> > > > + case DT_GNU_HASH: ghashtab = p; break;
> > > > case DT_VERSYM: versym = p; break;
> > > > case DT_VERDEF: verdef = p; break;
> > > > }
> > > > }
> > > >
> > > > - if (!strings || !syms || !hashtab) return 0;
> > > > + if (!strings || !syms) return 0;
> > > > if (!verdef) versym = 0;
> > > > + size_t nsym = 0;
> > > > +
> > > > + if (hashtab) nsym = hashtab[1];
> > > > + else if (ghashtab) nsym = count_syms_gnu(ghashtab);
> > > >
> > > > - for (i=0; i<hashtab[1]; i++) {
> > > > + for (i=0; i<nsym; i++) {
> > > > if (!(1<<(syms[i].st_info&0xf) & OK_TYPES)) continue;
> > > > if (!(1<<(syms[i].st_info>>4) & OK_BINDS)) continue;
> > > > if (!syms[i].st_shndx) continue;
> > > > --
> > > > 2.46.0
> > >
> > > Thanks! I don't see anything obviously wrong with this. I'll take a
> > > more detailed look over it soon. Are you hoping to get it included in
> > > this release cycle?
> > >
> > > Rich
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [musl] [PATCH v3] vdso: add support for GNU hash tables
2025-11-12 17:17 ` Rich Felker
@ 2025-11-12 19:45 ` Markus Wichmann
0 siblings, 0 replies; 6+ messages in thread
From: Markus Wichmann @ 2025-11-12 19:45 UTC (permalink / raw)
To: musl; +Cc: Tomáš Hulata
Am Wed, Nov 12, 2025 at 12:17:40PM -0500 schrieb Rich Felker:
> On Thu, Nov 06, 2025 at 10:59:45PM +0100, Tomáš Hulata wrote:
> > Hi Rich,
> > just reminding with this simple patch.
> > It would be great to get it merged.
> > Thanks
>
> Thanks for the ping! I was probably initially planning to hold off on
> this til a new release cycle, but I don't see any way it could break.
> It surely won't break on any kernel that has the standard ELF hash
> table available in the vdso like it should. If nobody has objections
> (I'd appreciate a second set of eyes from anyone willing to read it) I
> think this is ok to go ahead and apply.
>
> Rich
I just looked through the code and it seems correct. I paid special
attention to the header fields being decoded correctly, and they are.
Ciao,
Markus
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-11-12 19:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-22 22:54 [musl] [PATCH v3] vdso: add support for GNU hash tables tombo
2025-08-24 2:26 ` Rich Felker
2025-08-24 9:25 ` Tomáš Hulata
2025-11-06 21:59 ` Tomáš Hulata
2025-11-12 17:17 ` Rich Felker
2025-11-12 19:45 ` Markus Wichmann
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).