Subject: Re: bug#20614: Segmentation fault when building on Power8 Little Endian

From: Petr Hracek <[email-masked]>
Date: Mon, 5 Oct 2015 11:16:32 +0200

On 10/05/2015 10:27 AM, Eli Zaretskii wrote:
>> Cc: [email-masked]
>> From: Petr Hracek <[email-masked]>
>> Date: Mon, 5 Oct 2015 09:40:15 +0200
>>
>>>>>> What does this GDB command display in frame #1:
>>>>>>
>>>>>>      (gdb) p old_section_names + NEW_SECTION_H (nn).sh_name
>>>>>>
>>>>>> ?
>>>>>>
>>>>>> It is a really strange.
>>>>>> in our unexelf.c is NEW_SECTION_H defined as
>>>>>>
>>>>>> #define NEW_SECTION_H(n) \
>>>>>> (*(ElfW (Shdr) *) ((byte *) new_section_h + new_file_h->e_shentsize * (n)))
>>>>>>
>>>>>> Paul Eggert did a some patch 1 or 2 year ago and modify it to
>>>>>> #define NEW_SECTION_H(n) \
>>>>>>      (*(ElfW (Shdr) *) entry_address (new_section_h, n, new_file_h->e_shentsize))
>>>>>>
>>>>>> (gdb) frame 1
>>>>>> #1 0x00000000102e3724 in unexec (new_name=0x116387e8
>>>>>> "/home/phracek/rpmbuild/BUILD/emacs-24.3/src/emacs", old_name=0x11638838
>>>>>> "/home/phracek/rpmbuild/BUILD/emacs-24.3/src/temacs")
>>>>>> at unexelf.c:1258
>>>>>> 1258 if (!strcmp (old_section_names + NEW_SECTION_H (nn).sh_name, ".data")
>>>>>> (gdb) p old_section_names
>>>>>> $1 = 0x3fffab1dbfcc ""
>>>>>> (gdb) p old_section_names + NEW_SECTION_H (nn).sh_name
>>>>>> No symbol "NEW_SECTION_H" in current context.
>>>>> Use the expansion of that macro instead to display the value.
>>>> How to use the expansion.
>>> Just type it by hand:
>>>
>>>    (gdb) p old_section_names + (*(ElfW (Shdr) *) ((byte *) new_section_h + new_file_h->e_shentsize * (nn)))
>>>
>>>> Are you connected on freenode #emacs.
>>> No.
>> First of all thank you for your time.
>> Well,
>> (gdb) p (*(ElfW (Shdr) *) ((byte *) new_section_h +
>> new_file_h->e_shentsize * (nn)))
>> No symbol "ElfW" in current context.
>> (gdb)
>> Also ElfBitsW does not exists.
>> (gdb) p ElfBitsW
>> No symbol "ElfBitsW" in current context.
>> (gdb)
> You need to expand all these macros by hand.  They are defined at the
> beginning of unexelf.c:
>
>    #ifndef ElfW
>    # define ElfBitsW(bits, type) Elf##bits##_##type
>    # ifndef ELFSIZE
>    #  ifdef _LP64
>    #   define ELFSIZE 64
>    #  else
>    #   define ELFSIZE 32
>    #  endif
>    # endif
>      /* This macro expands `bits' before invoking ElfBitsW.  */
>    # define ElfExpandBitsW(bits, type) ElfBitsW (bits, type)
>    # define ElfW(type) ElfExpandBitsW (ELFSIZE, type)
>    #endif
>
> I would suggest at first to rebuild Emacs with "-gdwarf-4 -g3"
> compiler switches, maybe that will allow you to type expressions with
> macros, and let GDB expand them using the debug info.  Maybe.
Well, finally I have got it.
(gdb) p (*(ElfW (Shdr) *) ((byte *) new_section_h + 
new_file_h->e_shentsize * (nn)))
$1 = {sh_name = 1735746149, sh_type = 1650614623, sh_flags = 
7090183337103746418, sh_addr = 28550371716589429, sh_offset = 
8313477191008871470, sh_size = 8458434531098129012,
   sh_link = 1634885479, sh_info = 1936025454, sh_addralign = 
6874592421672660480, sh_entsize = 478660485485}
(gdb) p old_section_names + NEW_SECTION_H (nn).sh_name
$2 = 0x4000128ceb51 <Address 0x4000128ceb51 out of bounds>
(gdb) p old_section_names
$3 = 0x3fffab1788ec ""
(gdb)

Hope it helps.

-- 
Petr Hracek
Software Engineer
Developer Experience
Red Hat, Inc
Mob: +420777056169
email: [email-masked]