From c88db09cc5a93b527ab1c4320dd77666ab0c3aa7 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Thu, 6 Nov 2014 07:07:29 +0000 Subject: [PATCH] [Mips] Take into account that PIC code is inherently CPIC Follow-up to r221439. llvm-svn: 221442 --- lld/lib/ReaderWriter/ELF/Mips/MipsELFFlagsMerger.cpp | 9 +++++++-- lld/test/elf/Mips/e-flags-merge-3.test | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFlagsMerger.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFlagsMerger.cpp index 4db009d..47b6a98 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFlagsMerger.cpp +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFlagsMerger.cpp @@ -48,6 +48,11 @@ std::error_code MipsELFFlagsMerger::merge(uint8_t newClass, uint32_t newFlags) { if (newFlags & llvm::ELF::EF_MIPS_ARCH_ASE_M16) return make_dynamic_error_code(Twine("Unsupported extension: MIPS16")); + // PIC code is inherently CPIC and may not set CPIC flag explicitly. + // Ensure that this flag will exist in the linked file. + if (newFlags & llvm::ELF::EF_MIPS_PIC) + newFlags |= llvm::ELF::EF_MIPS_CPIC; + std::lock_guard lock(_mutex); // If the old set of flags is empty, use the new one as a result. @@ -64,10 +69,10 @@ std::error_code MipsELFFlagsMerger::merge(uint8_t newClass, uint32_t newFlags) { if ((newPic != 0) != (oldPic != 0)) llvm::errs() << "lld warning: linking abicalls and non-abicalls files\n"; - if (newPic != 0) - _flags |= llvm::ELF::EF_MIPS_CPIC; if (!(newPic & llvm::ELF::EF_MIPS_PIC)) _flags &= ~llvm::ELF::EF_MIPS_PIC; + if (newPic) + _flags |= llvm::ELF::EF_MIPS_CPIC; // Check mixing -mnan=2008 / -mnan=legacy modules. if ((newFlags & llvm::ELF::EF_MIPS_NAN2008) != diff --git a/lld/test/elf/Mips/e-flags-merge-3.test b/lld/test/elf/Mips/e-flags-merge-3.test index 4551eb1..e2d9f6c 100644 --- a/lld/test/elf/Mips/e-flags-merge-3.test +++ b/lld/test/elf/Mips/e-flags-merge-3.test @@ -23,9 +23,10 @@ # ABI-CALLS-WARN: lld warning: linking abicalls and non-abicalls files -# ABI-CALLS1: Flags [ (0x50001000) +# ABI-CALLS1: Flags [ (0x50001004) # ABI-CALLS1-NEXT: EF_MIPS_ABI_O32 (0x1000) # ABI-CALLS1-NEXT: EF_MIPS_ARCH_32 (0x50000000) +# ABI-CALLS1-NEXT: EF_MIPS_CPIC (0x4) # ABI-CALLS1-NEXT: ] # ABI-CALLS2: Flags [ (0x50001004) -- 2.7.4