[PATCH] ldso/x86_64: support protected symbols

Joakim Tjernlund joakim.tjernlund at transmode.se
Thu Apr 29 06:34:29 UTC 2010


>
>
> > On 04/27/2010 07:44 AM, Timo Teräs wrote:
> > > Joakim had a clean up patch for the above construct. See patch 1/2 of:
> > >  http://lists.uclibc.org/pipermail/uclibc/2010-April/043840.html
> > > (patch 2/2 there is wrong). See also rest of the thread.
> > >
> > > For some reason that did not got merged yet. Austin, care to merge
> > > that?
> > >
> > > But otherwise looks good.
> >
> > I was waiting for the discussion between you and Joakim to finish up and
> > a complete patch to come out of it, then I just sort of forgot about it.
> > Can someone resend the patch against current master? Thanks!
> >
> > Regarding the question you asked in that thread: When I added TLS
> > support in the i386 ldso, it was mostly based off of glibc code. I only
> > did cursory testing with it, and honestly am unsure about why that
> > particular check is there.
> >
> > ldso needs to have some more common code for sure, it's confusing and
> > incredibly hard to maintain now. But the more pressing need is to get
> > protected symbol support in for everybody that needs it.
> >
>
> Tried to wrap my head around this and PROTECTED definitively needs
> to move to common code. The best I can com up with is below.
> All callers needs to be updated with too. This is what
> I can do ATM. Hopefully you guys can manage from there.
>
>  Jocke
>
> diff --git a/ldso/ldso/dl-hash.c b/ldso/ldso/dl-hash.c
> index 0048734..ffaf953 100644
> --- a/ldso/ldso/dl-hash.c
> +++ b/ldso/ldso/dl-hash.c
> @@ -269,7 +269,7 @@ _dl_lookup_sysv_hash(struct elf_resolve *tpnt, ElfW(Sym)
> *symtab, unsigned long
>   * relocations or when we call an entry in the PLT table for the first time.
>   */
>  char *_dl_lookup_hash(const char *name, struct dyn_elf *rpnt, struct
> elf_resolve *mytpnt,
> -   int type_class, struct elf_resolve **tpntp)
> +            int type_class, struct elf_resolve **tpntp, const ElfW(Sym) *ref_sym)
>  {
>     struct elf_resolve *tpnt = NULL;
>     ElfW(Sym) *symtab;
> @@ -282,7 +282,11 @@ char *_dl_lookup_hash(const char *name, struct dyn_elf
> *rpnt, struct elf_resolve
>  #ifdef __LDSO_GNU_HASH_SUPPORT__
>     unsigned long gnu_hash_number = _dl_gnu_hash((const unsigned char *)name);
>  #endif
> -
> +   if (ELF32_ST_VISIBILITY(ref_sym->st_other) == STV_PROTECTED) {
> +      sym = ref_sym;
> +      tpnt = mytpnt;
> +      goto sym_found;
> +   }
>     for (; rpnt; rpnt = rpnt->next) {
>        tpnt = rpnt->dyn;
>
> @@ -332,7 +336,7 @@ char *_dl_lookup_hash(const char *name, struct dyn_elf
> *rpnt, struct elf_resolve
>        }
>  #endif
>     } /* end of for (; rpnt; rpnt = rpnt->next) { */
> -
> +sym_found:
>     if (sym) {
>        /* At this point we have found the requested symbol, do binding */
>  #if defined(USE_TLS) && USE_TLS
> diff --git a/ldso/ldso/x86_64/elfinterp.c b/ldso/ldso/x86_64/elfinterp.c
> index 54528d3..f8a0cb0 100644
> --- a/ldso/ldso/x86_64/elfinterp.c
> +++ b/ldso/ldso/x86_64/elfinterp.c
> @@ -56,21 +56,23 @@ _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
>     char **got_addr;
>     ElfW(Addr) instr_addr;
>     char *symname;
> +   ElfW(Sym) *sym;
>
>     rel_addr = (char *)tpnt->dynamic_info[DT_JMPREL];
>     this_reloc = (ELF_RELOC *)(rel_addr + reloc_entry);
>     symtab_index = ELF_R_SYM(this_reloc->r_info);
> -
>     symtab = (ElfW(Sym) *)tpnt->dynamic_info[DT_SYMTAB];
>     strtab = (char *)tpnt->dynamic_info[DT_STRTAB];
> -   symname = strtab + symtab[symtab_index].st_name;
> +   sym = &symtab[symtab_index];
> +   symname = strtab + sym->st_name;
>
>     /* Address of the jump instruction to fix up. */
>     instr_addr = (this_reloc->r_offset + tpnt->loadaddr);
>     got_addr = (char **)instr_addr;
>
>     /* Get the address of the GOT entry. */
> -   new_addr = _dl_find_hash(symname, tpnt->symbol_scope, tpnt,
> ELF_RTYPE_CLASS_PLT, NULL);
> +   new_addr = _dl_find_hash(symname, tpnt->symbol_scope, tpnt,
> +             ELF_RTYPE_CLASS_PLT, sym);
>     if (unlikely(!new_addr)) {
>        _dl_dprintf(2, "%s: Can't resolve symbol '%s'\n", _dl_progname, symname);
>        _dl_exit(1);
> @@ -174,7 +176,8 @@ _dl_do_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope,
>
>     if (symtab_index) {
>        symbol_addr = (ElfW(Addr))_dl_find_hash(symname, scope, tpnt,
> -            elf_machine_type_class(reloc_type), &tls_tpnt);
> +                     elf_machine_type_class(reloc_type),
> +                     &tls_tpnt, sym);
>        /*
>         * We want to allow undefined references to weak symbols - this
>         * might have been intentional.  We should not be linking local

Guys, I hope you are not waiting for me to complete this. I am too lazy
to build a working env. and got too little time.

     Jocke



More information about the uClibc mailing list