This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: calling an undefined weak symbol


Thank You Nix !

On 10/16/07, Nix <nix@esperi.org.uk> wrote:
> On 14 Oct 2007, Metuki Sabhe stated:
>
> > Hi list,
> >
> > In the function __libc_start_main we have those two lines:
> >
> > extern void __nptl_deallocate_tsd (void) __attribute ((weak));
> > __nptl_deallocate_tsd ();
> >
> > If I understand correctly, the function will call __nptl_deallocate_tsd,
> > which will have the value of the __nptl_deallocate_tsd function
> > if libpthread will be linked in, or zero if not (because this is a weak
> > symbol).
> > But, if libpthread is not linked in, then __libc_start_main will call
> > a value of zero which will make a Segmentation Fault !
>
> Indeed: only, as you suspected, this can never happen.
>
> > Can you please explain this to me (I don't really think glibc creates
> > a segfault, I am sure I missed something here) ?
>
> Look a few lines up:
>
>  int not_first_call;
>  not_first_call = setjmp ((struct __jmp_buf_tag *) unwind_buf.cancel_jmp_buf);
>  if (__builtin_expect (! not_first_call, 1))
>
> The code you note is in an else branch of that if block. i.e., that code
> is only invoked if the cancel_jmp_buf is jumped to, and as its name
> indicates this is part of the cancellation point mechanism, and is only
> otherwise referenced by NPTL code.
>
> So it's quite safe, and if we enter that else branch we *must* be in a
> program linked with -lpthread.
>
> (The code you note is actually the !SHARED branch; the SHARED branch
> makes the same assumptions, but does it by way of a thunk through an
> NPTL structure filled with function pointers.)
>
> --
> `Some people don't think performance issues are "real bugs", and I think
> such people shouldn't be allowed to program.' --- Linus Torvalds
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]