On Sat, Jul 13, 2024 at 7:52 PM Max Filippov <jcmvb...@gmail.com> wrote: > > On Wed, Jul 10, 2024 at 12:49 PM Ian Lance Taylor <i...@google.com> wrote: > > On Sun, May 26, 2024 at 11:51 PM Max Filippov <jcmvb...@gmail.com> wrote: > > > diff --git a/libbacktrace/internal.h b/libbacktrace/internal.h > > > index 4fa0af8cb6c9..456911166026 100644 > > > --- a/libbacktrace/internal.h > > > +++ b/libbacktrace/internal.h > > > @@ -323,10 +323,22 @@ struct dwarf_sections > > > > > > struct dwarf_data; > > > > > > +#if defined (HAVE_DL_ITERATE_PHDR) && defined (__FDPIC__) > > > +typedef struct elf32_fdpic_loadaddr base_address_type; > > > +#define __RELOC_UINTPTR(ptr, base) ((uintptr_t)__RELOC_POINTER (ptr, > > > base)) > > > +#define no_base_address ((struct elf32_fdpic_loadaddr){0}) > > > +#else > > > +typedef uintptr_t base_address_type; > > > +#define __RELOC_POINTER(ptr, base) ((ptr) + (base)) > > > +#define __RELOC_UINTPTR(ptr, base) ((uintptr_t)__RELOC_POINTER (ptr, > > > base)) > > > +#define no_base_address ((uintptr_t)0) > > > +#endif > > > + > > > + > > > > When I look at the uClibc sources, I don't understand how this works. > > This sets no_base_address to have a zero map field. But > > __RELOC_POINTER will crash when given a zero map field. > > That's right. But __RELOC_POINTER should never be called for base > address set to no_base_address, that's what the following hunk ensures: > > --->8--- > @@ -6636,9 +6636,15 @@ elf_add (struct backtrace_state *state, const > char *filename, int descriptor, > > /* If the executable is ET_DYN, it is either a PIE, or we are running > directly a shared library with .interp. We need to wait for > - dl_iterate_phdr in that case to determine the actual base_address. */ > + dl_iterate_phdr in that case to determine the actual base_address. > + In case of FDPIC we always need the actual base_address. */ > +#ifndef __FDPIC__ > if (exe && ehdr.e_type == ET_DYN) > return -1; > +#else > + if (exe) > + return -1; > +#endif > > shoff = ehdr.e_shoff; > shnum = ehdr.e_shnum;
I see. The code is using dl_iterate_phdr for everything. This is a confusing execution flow. It means that we do some pointless work. Ian