[MIPS] Fix PLT entries generation in case of linking regular and microMIPS code
authorSimon Atanasyan <simon@atanasyan.com>
Mon, 2 Oct 2017 14:56:41 +0000 (14:56 +0000)
committerSimon Atanasyan <simon@atanasyan.com>
Mon, 2 Oct 2017 14:56:41 +0000 (14:56 +0000)
commit649e4d328f1569f92b4dcec4f25437fbbf21816a
treec211b3e511ee1ca810764c4034fe3247f9f5a91f
parent01e5320c484ae87b524e1942c0f668397a4ef606
[MIPS] Fix PLT entries generation in case of linking regular and microMIPS code

Currently LLD calls the `isMicroMips` routine to determine type of PLT entries
needs to be generated: regular or microMIPS. This routine checks ELF
header flags in the `FirstObj` to retrieve type of linked object files.
So if the first file does not contain microMIPS code, LLD will generate
PLT entries with regular (non-microMIPS) code only.

Ideally, if a PLT entry is referenced by microMIPS code only this entry
should contain microMIPS code, if a PLT entry is referenced by regular
code this entry should contain regular code. In a "mixed" case the PLT
entry can be either microMIPS or regular, but each "cross-mode-call" has
additional cost.

It's rather difficult to implement this ideal solution. But we can
assume that if there is an input object file with microMIPS code, the
most part of the code is microMIPS too. So we need to deduce type of PLT
entries based on finally calculated ELF header flags and do not check
only the first input object file.

This change implements this.
  - The `getMipsEFlags` renamed to the `calcMipsEFlags`. The function
    called from the `LinkerDriver::link`. Result is stored in
    the Configuration::MipsEFlags field.
  - The `isMicroMips` and `isMipsR6` routines access the `MipsEFlags`
    field to get and check calculated ELF flags.
  - New types of PLT records created when necessary.

Differential revision: https://reviews.llvm.org/D37747

llvm-svn: 314675
lld/ELF/Arch/Mips.cpp
lld/ELF/Arch/MipsArchTree.cpp
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/SyntheticSections.cpp
lld/ELF/Writer.cpp
lld/ELF/Writer.h
lld/test/ELF/mips-elf-flags.s
lld/test/ELF/mips-micro-jal.s