[lld] r234635 - [Mips] Add -pcrel-eh-reloc command line option

Rui Ueyama ruiu at google.com
Fri Apr 10 14:14:12 PDT 2015


On Fri, Apr 10, 2015 at 2:00 PM, Simon Atanasyan <simon at atanasyan.com>
wrote:

> Author: atanasyan
> Date: Fri Apr 10 16:00:41 2015
> New Revision: 234635
>
> URL: http://llvm.org/viewvc/llvm-project?rev=234635&view=rev
> Log:
> [Mips] Add -pcrel-eh-reloc command line option
>
> This MIPS specific option controls R_MIPS_EH relocation handling.
> If -pcrel-eh-reloc is specified R_MIPS_EH relocation should be handled
> like R_MIPS_PC32 relocation.
>
> Added:
>     lld/trunk/test/elf/Mips/rel-eh-03.test
> Modified:
>     lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h
>     lld/trunk/lib/Driver/GnuLdDriver.cpp
>     lld/trunk/lib/Driver/GnuLdOptions.td
>     lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp
>
> Modified: lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h?rev=234635&r1=234634&r2=234635&view=diff
>
> ==============================================================================
> --- lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h (original)
> +++ lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h Fri Apr 10
> 16:00:41 2015
> @@ -326,6 +326,10 @@ public:
>    bool armTarget1Rel() const { return _armTarget1Rel; }
>    void setArmTarget1Rel(bool value) { _armTarget1Rel = value; }
>
> +  // Set R_MIPS_EH relocation behaviour.
> +  bool mipsPcRelEhRel() const { return _mipsPcRelEhRel; }
> +  void setMipsPcRelEhRel(bool value) { _mipsPcRelEhRel = value; }
> +
>    /// Each time a reader reads a new file, this member function is called
>    /// with the file's ELF magics. This is supposed to "merge" all
> attributes
>    /// to generate output ELF file magic. This can also reject input files
> @@ -361,6 +365,7 @@ protected:
>    bool _enableNewDtags = false;
>    bool _collectStats = false;
>    bool _armTarget1Rel = false;
> +  bool _mipsPcRelEhRel = false;
>    uint64_t _maxPageSize = 0x1000;
>
>    OutputMagic _outputMagic;
>
> Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=234635&r1=234634&r2=234635&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
> +++ lld/trunk/lib/Driver/GnuLdDriver.cpp Fri Apr 10 16:00:41 2015
> @@ -557,6 +557,19 @@ bool GnuLdDriver::parse(int argc, const
>           << "--arm-target1-abs\n";
>    }
>
> +  // Process MIPS specific options.
> +  if (triple.getArch() == llvm::Triple::mips ||
> +      triple.getArch() == llvm::Triple::mipsel ||
> +      triple.getArch() == llvm::Triple::mips64 ||
> +      triple.getArch() == llvm::Triple::mips64el)
> +    ctx->setMipsPcRelEhRel(parsedArgs->hasArg(OPT_pcrel_eh_reloc));
> +  else {
> +    for (const auto *arg : parsedArgs->filtered(OPT_grp_mips_targetopts))
> {
> +      diag << "warning: ignoring unsupported MIPS specific argument: "
> +           << arg->getSpelling() << "\n";
> +    }
> +  }
> +
>    for (auto *arg : parsedArgs->filtered(OPT_L))
>      ctx->addSearchPath(arg->getValue());
>
>
> Modified: lld/trunk/lib/Driver/GnuLdOptions.td
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdOptions.td?rev=234635&r1=234634&r2=234635&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/Driver/GnuLdOptions.td (original)
> +++ lld/trunk/lib/Driver/GnuLdOptions.td Fri Apr 10 16:00:41 2015
> @@ -329,6 +329,15 @@ def arm_target1_abs : Flag<["--"], "arm-
>       Group<grp_targetopts>, HelpText<"Interpret R_ARM_TARGET1 as
> R_ARM_ABS32">;
>
>
>  //===----------------------------------------------------------------------===//
> +/// MIPS Target Specific Options
>
> +//===----------------------------------------------------------------------===//
> +def grp_mips_targetopts : OptionGroup<"MIPS SPECIFIC OPTIONS">,
> +     Group<grp_targetopts>;
> +def pcrel_eh_reloc : Flag<["-", "--"], "pcrel-eh-reloc">,
> +     Group<grp_mips_targetopts>,
> +     HelpText<"Interpret R_MIPS_EH as R_MIPS_PC32">;
> +
>
> +//===----------------------------------------------------------------------===//
>  /// Ignored options
>
>  //===----------------------------------------------------------------------===//
>  def grp_ignored: OptionGroup<"ignored">,
>
> Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp?rev=234635&r1=234634&r2=234635&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp (original)
> +++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp Fri Apr 10
> 16:00:41 2015
> @@ -599,6 +599,9 @@ void RelocationPass<ELFT>::collectRefere
>      return;
>
>    auto refKind = ref.kindValue();
> +  if (refKind == R_MIPS_EH && this->_ctx.mipsPcRelEhRel())
> +    ref.setKindValue(R_MIPS_PC32);
> +
>    if (!isConstrainSym(atom, refKind))
>      return;
>
>
> Added: lld/trunk/test/elf/Mips/rel-eh-03.test
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/rel-eh-03.test?rev=234635&view=auto
>
> ==============================================================================
> --- lld/trunk/test/elf/Mips/rel-eh-03.test (added)
> +++ lld/trunk/test/elf/Mips/rel-eh-03.test Fri Apr 10 16:00:41 2015
> @@ -0,0 +1,128 @@
> +# Check R_MIPS_EH relocation handling in case of -pcrel-eh-reloc option.
> +
> +# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.o
> +# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.o
> +# RUN: lld -flavor gnu -target mipsel -e T0 \
> +# RUN:     -pcrel-eh-reloc -o %t.exe %t1.o %t2.o %t.so
>

This test fails because %t.so does not exist. Can you fix the issue?


> +# RUN: llvm-objdump -s -t %t.exe | FileCheck -check-prefix=RAW %s
> +
> +# RAW:      Contents of section .gnu_extab:
> +# RAW-NEXT:  400158 00e7ffff ff000000 a01e0000 00000000
> +#                     ^ 0x400140 + 0 - 0x400159 = 0xffffffe7
> +#                                     ^ 0x402000 + 0 - 0x400160 = 0x1ea0
> +#           E1 GOT entry = 0xffff8020 = -32736 ^
> +# RAW:      Contents of section .got:
> +# RAW-NEXT:  401000 00000000 00000080
> +
> +# RAW: SYMBOL TABLE:
> +# RAW: 00402000 l    .data  00000004 L1
> +# RAW: 00400140 g  F .text  00000004 T1
> +
> +# t1.o
> +---
> +FileHeader:
> +  Class:   ELFCLASS32
> +  Data:    ELFDATA2LSB
> +  Type:    ET_REL
> +  Machine: EM_MIPS
> +  Flags:   [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_PIC,
> +            EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
> +
> +Sections:
> +  - Name:          .text
> +    Type:          SHT_PROGBITS
> +    Flags:         [SHF_ALLOC, SHF_EXECINSTR]
> +    AddressAlign:  16
> +    Size:          4
> +
> +Symbols:
> +  Global:
> +    - Name:    T1
> +      Type:    STT_FUNC
> +      Section: .text
> +      Value:   0
> +      Size:    4
> +
> +# t2.o
> +---
> +FileHeader:
> +  Class:   ELFCLASS32
> +  Data:    ELFDATA2LSB
> +  Type:    ET_REL
> +  Machine: EM_MIPS
> +  Flags:   [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_PIC,
> +            EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
> +
> +Sections:
> +  - Name:          .text
> +    Type:          SHT_PROGBITS
> +    Flags:         [SHF_ALLOC, SHF_EXECINSTR]
> +    AddressAlign:  16
> +    Size:          8
> +
> +  - Name:          .data
> +    Type:          SHT_PROGBITS
> +    Flags:         [SHF_WRITE, SHF_ALLOC]
> +    AddressAlign:  16
> +    Size:          4
> +
> +  - Name:          .gnu_extab
> +    Type:          SHT_PROGBITS
> +    Flags:         [SHF_ALLOC]
> +    AddressAlign:  4
> +    Size:          16
> +
> +  - Name:          .rel.gnu_extab
> +    Type:          SHT_REL
> +    Link:          .symtab
> +    AddressAlign:  4
> +    Info:          .gnu_extab
> +    Relocations:
> +      - Offset:  1
> +        Symbol:  T1
> +        Type:    R_MIPS_EH
> +      - Offset:  8
> +        Symbol:  L1
> +        Type:    R_MIPS_EH
> +
> +  - Name:          .eh_frame_entry
> +    Type:          SHT_PROGBITS
> +    Flags:         [SHF_ALLOC]
> +    AddressAlign:  4
> +    Content:       "0000000100000001"
> +
> +  - Name:          .rel.eh_frame_entry
> +    Type:          SHT_REL
> +    Link:          .symtab
> +    AddressAlign:  4
> +    Info:          .eh_frame_entry
> +    Relocations:
> +      - Offset:  0
> +        Symbol:  .text
> +        Type:    R_MIPS_PC32
> +      - Offset:  4
> +        Symbol:  .gnu_extab
> +        Type:    R_MIPS_PC32
> +
> +Symbols:
> +  Local:
> +    - Name:    .text
> +      Type:    STT_SECTION
> +      Section: .text
> +    - Name:    .gnu_extab
> +      Type:    STT_SECTION
> +      Section: .gnu_extab
> +    - Name:    L1
> +      Type:    STT_OBJECT
> +      Section: .data
> +      Value:   0
> +      Size:    4
> +
> +  Global:
> +    - Name:    T0
> +      Type:    STT_FUNC
> +      Section: .text
> +      Value:   0
> +      Size:    8
> +    - Name:    T1
> +...
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150410/8319d369/attachment.html>


More information about the llvm-commits mailing list