[llvm] r359311 - [llvm-nm] Fix handling of symbol types 't' 'd' 'r'
Jordan Rupprecht via llvm-commits
llvm-commits at lists.llvm.org
Fri May 3 13:59:54 PDT 2019
Ok. I think if we can confirm that it's a bug with GNU nm, then we can go
ahead and roll forward this change.
On Thu, May 2, 2019 at 5:49 PM Fāng-ruì Sòng <maskray at google.com> wrote:
> This is actually a GNU nm bug and the bug was introduced in
> https://reviews.llvm.org/D26937
>
>
> https://sourceware.org/git/?p=binutils-gdb.git;a=blob;hb=41f61c65a2e1cfdb4aca3bccf6e11025495ba02e;f=bfd/syms.c#l582
> checks ".init" but fails to check ".init_array". ".init_array" contains
> pointers just like ".pre_init_array". You may notice that GNU nm prints:
>
> t __init_array_start
> d __preinit_array_start
>
>
>
> On Fri, May 3, 2019 at 5:27 AM Jordan Rupprecht <rupprecht at google.com>
> wrote:
>
>> This change is actually a regression, __init_array_start/__init_array_end
>> show up as 'd' now instead of 't'. (nm <large file> used to be identical to
>> llvm-nm, modulo sorting).
>>
>> Can you send changes like this for review first, and reserve post-commit
>> review for NFCs or other minor changes?
>>
>> On Fri, Apr 26, 2019 at 8:59 AM Fangrui Song via llvm-commits <
>> llvm-commits at lists.llvm.org> wrote:
>>
>>> Author: maskray
>>> Date: Fri Apr 26 09:01:48 2019
>>> New Revision: 359311
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=359311&view=rev
>>> Log:
>>> [llvm-nm] Fix handling of symbol types 't' 'd' 'r'
>>>
>>> In addition, fix and convert the two tests to yaml2obj based. This
>>> allows us to delete two executables.
>>>
>>> X86/weak.test: 'v' was not tested
>>> X86/init-fini.test: symbol types of __bss_start _edata _end were wrong
>>> GNU nm reports __init_array_start as 't', and __preinit_array_start as
>>> 'd'.
>>> __init_array_start is 't' just because its section ".init_array"
>>> starts with ".init"
>>>
>>> 'd' makes more sense and allows us to drop the weird SHT_INIT_ARRAY
>>> rule.
>>> So, change __init_array_start to 'd' instead.
>>>
>>> Removed:
>>> llvm/trunk/test/tools/llvm-nm/X86/Inputs/init-fini.out.elf-x86_64
>>> llvm/trunk/test/tools/llvm-nm/X86/Inputs/weak.obj.elf-x86_64
>>> Modified:
>>> llvm/trunk/test/tools/llvm-nm/X86/init-fini.test
>>> llvm/trunk/test/tools/llvm-nm/X86/weak.test
>>> llvm/trunk/tools/llvm-nm/llvm-nm.cpp
>>>
>>> Removed:
>>> llvm/trunk/test/tools/llvm-nm/X86/Inputs/init-fini.out.elf-x86_64
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/X86/Inputs/init-fini.out.elf-x86_64?rev=359310&view=auto
>>>
>>> ==============================================================================
>>> Binary files
>>> llvm/trunk/test/tools/llvm-nm/X86/Inputs/init-fini.out.elf-x86_64
>>> (original) and
>>> llvm/trunk/test/tools/llvm-nm/X86/Inputs/init-fini.out.elf-x86_64 (removed)
>>> differ
>>>
>>> Removed: llvm/trunk/test/tools/llvm-nm/X86/Inputs/weak.obj.elf-x86_64
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/X86/Inputs/weak.obj.elf-x86_64?rev=359310&view=auto
>>>
>>> ==============================================================================
>>> Binary files
>>> llvm/trunk/test/tools/llvm-nm/X86/Inputs/weak.obj.elf-x86_64 (original) and
>>> llvm/trunk/test/tools/llvm-nm/X86/Inputs/weak.obj.elf-x86_64 (removed)
>>> differ
>>>
>>> Modified: llvm/trunk/test/tools/llvm-nm/X86/init-fini.test
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/X86/init-fini.test?rev=359311&r1=359310&r2=359311&view=diff
>>>
>>> ==============================================================================
>>> --- llvm/trunk/test/tools/llvm-nm/X86/init-fini.test (original)
>>> +++ llvm/trunk/test/tools/llvm-nm/X86/init-fini.test Fri Apr 26 09:01:48
>>> 2019
>>> @@ -1,8 +1,50 @@
>>> -# RUN: llvm-nm -B -S %p/Inputs/init-fini.out.elf-x86_64 | FileCheck
>>> --match-full-lines %s
>>> +# RUN: yaml2obj %s -o %t
>>> +# RUN: llvm-nm -B -S %t | FileCheck %s
>>> +!ELF
>>> +FileHeader:
>>> + Class: ELFCLASS64
>>> + Data: ELFDATA2LSB
>>> + Type: ET_EXEC
>>> + Machine: EM_X86_64
>>> +Sections:
>>> + - Name: .text
>>> + Type: SHT_PROGBITS
>>> + Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
>>> + - Name: .init_array
>>> + Type: SHT_INIT_ARRAY
>>> + Flags: [ SHF_ALLOC, SHF_WRITE ]
>>> + - Name: .preinit_array
>>> + Type: SHT_PREINIT_ARRAY
>>> + Flags: [ SHF_ALLOC, SHF_WRITE ]
>>> + - Name: .fini_array
>>> + Type: SHT_FINI_ARRAY
>>> + Flags: [ SHF_ALLOC, SHF_WRITE ]
>>> + - Name: .data
>>> + Type: SHT_PROGBITS
>>> + Flags: [ SHF_ALLOC, SHF_WRITE ]
>>> + - Name: .bss
>>> + Type: SHT_NOBITS
>>> + Flags: [ SHF_ALLOC, SHF_WRITE ]
>>> +Symbols:
>>> + - Name: __init_array_start
>>> + Section: .init_array
>>> + - Name: __preinit_array_start
>>> + Section: .preinit_array
>>> + - Name: __fini_array_start
>>> + Section: .fini_array
>>> + - Name: __bss_start
>>> + Section: .bss
>>> + Binding: STB_GLOBAL
>>> + - Name: _edata
>>> + Section: .data
>>> + Binding: STB_GLOBAL
>>> + - Name: _end
>>> + Section: .bss
>>> + Binding: STB_GLOBAL
>>>
>>> -CHECK: 00000000006000c2 0000000000000000 T __bss_start
>>> -CHECK: 00000000006000c2 0000000000000000 t __init_array_end
>>> -CHECK: 00000000006000ba 0000000000000000 t __init_array_start
>>> -CHECK: 00000000006000c2 0000000000000000 T _edata
>>> -CHECK: 00000000006000c8 0000000000000000 T _end
>>> -CHECK: 00000000004000b0 0000000000000000 T _start
>>> +# CHECK: B __bss_start
>>> +# CHECK: d __fini_array_start
>>> +# CHECK: d __init_array_start
>>> +# CHECK: d __preinit_array_start
>>> +# CHECK: D _edata
>>> +# CHECK: B _end
>>>
>>> Modified: llvm/trunk/test/tools/llvm-nm/X86/weak.test
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/X86/weak.test?rev=359311&r1=359310&r2=359311&view=diff
>>>
>>> ==============================================================================
>>> --- llvm/trunk/test/tools/llvm-nm/X86/weak.test (original)
>>> +++ llvm/trunk/test/tools/llvm-nm/X86/weak.test Fri Apr 26 09:01:48 2019
>>> @@ -1,7 +1,36 @@
>>> -# RUN: llvm-nm -B -S %p/Inputs/weak.obj.elf-x86_64 | FileCheck
>>> --match-full-lines %s
>>> -# RUN: llvm-nm -W -B -S %p/Inputs/weak.obj.elf-x86_64 | count 0
>>> +# RUN: yaml2obj %s -o %t
>>> +# RUN: llvm-nm -B -S %t | FileCheck --match-full-lines %s
>>> +# RUN: llvm-nm -W -B -S %t | count 0
>>> +!ELF
>>> +FileHeader:
>>> + Class: ELFCLASS64
>>> + Data: ELFDATA2LSB
>>> + Type: ET_REL
>>> + Machine: EM_X86_64
>>> +Sections:
>>> + - Name: .text
>>> + Type: SHT_PROGBITS
>>> + - Name: .data
>>> + Type: SHT_PROGBITS
>>> +Symbols:
>>> + - Name: weak_func
>>> + Type: STT_FUNC
>>> + Section: .text
>>> + Binding: STB_WEAK
>>> + Size: 17
>>> + - Name: weak_var
>>> + Type: STT_OBJECT
>>> + Section: .data
>>> + Binding: STB_WEAK
>>> + Size: 4
>>> + - Name: weak_extern_func
>>> + Type: STT_FUNC
>>> + Binding: STB_WEAK
>>> + - Name: weak_extern_var
>>> + Type: STT_OBJECT
>>> + Binding: STB_WEAK
>>>
>>> -CHECK: w weak_extern_func
>>> -CHECK: w weak_extern_var
>>> -CHECK: 0000000000000000 0000000000000011 W weak_func
>>> -CHECK: 0000000000000000 0000000000000004 V weak_var
>>> +# CHECK: w weak_extern_func
>>> +# CHECK: v weak_extern_var
>>> +# CHECK: 0000000000000000 0000000000000011 W weak_func
>>> +# CHECK: 0000000000000000 0000000000000004 V weak_var
>>>
>>> Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=359311&r1=359310&r2=359311&view=diff
>>>
>>> ==============================================================================
>>> --- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
>>> +++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Fri Apr 26 09:01:48 2019
>>> @@ -936,27 +936,14 @@ static char getSymbolNMTypeChar(ELFObjec
>>>
>>> elf_section_iterator SecI = *SecIOrErr;
>>> if (SecI != Obj.section_end()) {
>>> - switch (SecI->getType()) {
>>> - case ELF::SHT_PROGBITS:
>>> - case ELF::SHT_DYNAMIC:
>>> - switch (SecI->getFlags()) {
>>> - case (ELF::SHF_ALLOC | ELF::SHF_EXECINSTR):
>>> - return 't';
>>> - case (ELF::SHF_TLS | ELF::SHF_ALLOC | ELF::SHF_WRITE):
>>> - case (ELF::SHF_ALLOC | ELF::SHF_WRITE):
>>> - return 'd';
>>> - case ELF::SHF_ALLOC:
>>> - case (ELF::SHF_ALLOC | ELF::SHF_MERGE):
>>> - case (ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::SHF_STRINGS):
>>> - return 'r';
>>> - }
>>> - break;
>>> - case ELF::SHT_NOBITS:
>>> + uint32_t Type = SecI->getType();
>>> + uint64_t Flags = SecI->getFlags();
>>> + if (Type == ELF::SHT_NOBITS)
>>> return 'b';
>>> - case ELF::SHT_INIT_ARRAY:
>>> - case ELF::SHT_FINI_ARRAY:
>>> + if (Flags & ELF::SHF_EXECINSTR)
>>> return 't';
>>> - }
>>> + if (Flags & ELF::SHF_ALLOC)
>>> + return Flags & ELF::SHF_WRITE ? 'd' : 'r';
>>> }
>>>
>>> if (SymI->getELFType() == ELF::STT_SECTION) {
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at lists.llvm.org
>>> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>>
>>
>
> --
> 宋方睿
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190503/97d5151c/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4849 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190503/97d5151c/attachment-0001.bin>
More information about the llvm-commits
mailing list