[llvm] r293224 - [obj2yaml] Produce correct output for invalid relocations.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 27 10:27:57 PST 2017


Passing the result object back via yam2obj will produce a different
result, no?


Davide Italiano via llvm-commits <llvm-commits at lists.llvm.org> writes:

> Author: davide
> Date: Thu Jan 26 17:12:53 2017
> New Revision: 293224
>
> URL: http://llvm.org/viewvc/llvm-project?rev=293224&view=rev
> Log:
> [obj2yaml] Produce correct output for invalid relocations.
>
> R_X86_64_NONE can be emitted without a symbol associated (well,
> in theory it should never be emitted in an ABI-compliant relocatable
> object). So, if there's no symbol associated to a reloc, emit one
> with an empty name, instead of crashing.
>
> Ack'ed by Michael Spencer offline.
>
> PR: 31768
>
> Added:
>     llvm/trunk/test/Object/Inputs/invalid-reloc.elf-x86-64
>     llvm/trunk/test/Object/obj2yaml-invalid-reloc.test
> Modified:
>     llvm/trunk/tools/obj2yaml/elf2yaml.cpp
>
> Added: llvm/trunk/test/Object/Inputs/invalid-reloc.elf-x86-64
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/invalid-reloc.elf-x86-64?rev=293224&view=auto
> ==============================================================================
> Binary files llvm/trunk/test/Object/Inputs/invalid-reloc.elf-x86-64 (added) and llvm/trunk/test/Object/Inputs/invalid-reloc.elf-x86-64 Thu Jan 26 17:12:53 2017 differ
>
> Added: llvm/trunk/test/Object/obj2yaml-invalid-reloc.test
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/obj2yaml-invalid-reloc.test?rev=293224&view=auto
> ==============================================================================
> --- llvm/trunk/test/Object/obj2yaml-invalid-reloc.test (added)
> +++ llvm/trunk/test/Object/obj2yaml-invalid-reloc.test Thu Jan 26 17:12:53 2017
> @@ -0,0 +1,37 @@
> +RUN: obj2yaml %p/Inputs/invalid-reloc.elf-x86-64 | FileCheck %s
> +
> +CHECK: --- !ELF
> +CHECK-NEXT: FileHeader:
> +CHECK-NEXT:   Class:           ELFCLASS64
> +CHECK-NEXT:   Data:            ELFDATA2LSB
> +CHECK-NEXT:   OSABI:           ELFOSABI_FREEBSD
> +CHECK-NEXT:   Type:            ET_REL
> +CHECK-NEXT:   Machine:         EM_X86_64
> +CHECK-NEXT: Sections:
> +CHECK-NEXT:   - Name:            .text
> +CHECK-NEXT:     Type:            SHT_PROGBITS
> +CHECK-NEXT:     Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
> +CHECK-NEXT:     AddressAlign:    0x0000000000000004
> +CHECK-NEXT:     Content:         4833C0C390
> +CHECK-NEXT:   - Name:            .rela.text
> +CHECK-NEXT:     Type:            SHT_RELA
> +CHECK-NEXT:     Link:            .symtab
> +CHECK-NEXT:     AddressAlign:    0x0000000000000008
> +CHECK-NEXT:     Info:            .text
> +CHECK-NEXT:     Relocations:
> +CHECK-NEXT:       - Offset:          0x0000000000000000
> +CHECK-NEXT:         Symbol:          ''
> +CHECK-NEXT:         Type:            R_X86_64_NONE
> +CHECK-NEXT: Symbols:
> +CHECK-NEXT:   Local:
> +CHECK-NEXT:     - Name:            rb_ary_new_capa
> +CHECK-NEXT:       Type:            STT_FUNC
> +CHECK-NEXT:       Section:         .text
> +CHECK-NEXT:       Size:            0x0000000000000005
> +CHECK-NEXT:   Global:
> +CHECK-NEXT:     - Name:            __dtraceenabled_ruby___array-create
> +CHECK-NEXT:     - Name:            '$dtrace1316529.rb_ary_new_capa'
> +CHECK-NEXT:       Type:            STT_FUNC
> +CHECK-NEXT:       Section:         .text
> +CHECK-NEXT:       Size:            0x0000000000000005
> +CHECK-NEXT:       Visibility:      STV_HIDDEN
>
> Modified: llvm/trunk/tools/obj2yaml/elf2yaml.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/elf2yaml.cpp?rev=293224&r1=293223&r2=293224&view=diff
> ==============================================================================
> --- llvm/trunk/tools/obj2yaml/elf2yaml.cpp (original)
> +++ llvm/trunk/tools/obj2yaml/elf2yaml.cpp Thu Jan 26 17:12:53 2017
> @@ -228,10 +228,18 @@ std::error_code ELFDumper<ELFT>::dumpRel
>      return errorToErrorCode(StrTabOrErr.takeError());
>    StringRef StrTab = *StrTabOrErr;
>  
> -  Expected<StringRef> NameOrErr = Sym->getName(StrTab);
> -  if (!NameOrErr)
> -    return errorToErrorCode(NameOrErr.takeError());
> -  R.Symbol = NameOrErr.get();
> +  if (Sym) {
> +    Expected<StringRef> NameOrErr = Sym->getName(StrTab);
> +    if (!NameOrErr)
> +      return errorToErrorCode(NameOrErr.takeError());
> +    R.Symbol = NameOrErr.get();
> +  } else {
> +    // We have some edge cases of relocations without a symbol associated,
> +    // e.g. an object containing the invalid (according to the System V
> +    // ABI) R_X86_64_NONE reloc. Create a symbol with an empty name instead
> +    // of crashing.
> +    R.Symbol = "";
> +  }
>  
>    return obj2yaml_error::success;
>  }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list