From e774126c9623639b11f8716dee9e49cb2d97649b Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Wed, 3 Feb 2016 11:50:22 +0000 Subject: [PATCH] [mips] Add SHF_MIPS_GPREL flag to the MIPS .sbss and .sdata sections MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit MIPS ABI states that .sbss and .sdata sections must have SHF_MIPS_GPREL flag. See Figure 4–7 on page 69 in the following document: ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf. Differential Revision: http://reviews.llvm.org/D15740 llvm-svn: 259641 --- llvm/lib/Target/Mips/MipsTargetObjectFile.cpp | 6 ++++-- llvm/test/CodeGen/Mips/mips-shf-gprel.ll | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 llvm/test/CodeGen/Mips/mips-shf-gprel.ll diff --git a/llvm/lib/Target/Mips/MipsTargetObjectFile.cpp b/llvm/lib/Target/Mips/MipsTargetObjectFile.cpp index 79df9a0..e83abdd 100644 --- a/llvm/lib/Target/Mips/MipsTargetObjectFile.cpp +++ b/llvm/lib/Target/Mips/MipsTargetObjectFile.cpp @@ -41,10 +41,12 @@ void MipsTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){ InitializeELF(TM.Options.UseInitArray); SmallDataSection = getContext().getELFSection( - ".sdata", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC); + ".sdata", ELF::SHT_PROGBITS, + ELF::SHF_WRITE | ELF::SHF_ALLOC | ELF::SHF_MIPS_GPREL); SmallBSSSection = getContext().getELFSection(".sbss", ELF::SHT_NOBITS, - ELF::SHF_WRITE | ELF::SHF_ALLOC); + ELF::SHF_WRITE | ELF::SHF_ALLOC | + ELF::SHF_MIPS_GPREL); this->TM = &static_cast(TM); } diff --git a/llvm/test/CodeGen/Mips/mips-shf-gprel.ll b/llvm/test/CodeGen/Mips/mips-shf-gprel.ll new file mode 100644 index 0000000..8b5fbaa --- /dev/null +++ b/llvm/test/CodeGen/Mips/mips-shf-gprel.ll @@ -0,0 +1,24 @@ +; Check that .sdata section has SHF_MIPS_GPREL flag. + +; RUN: llc -mips-ssection-threshold=16 -mgpopt -mattr=noabicalls \ +; RUN: -relocation-model=static -march=mips -o - %s -filetype=obj \ +; RUN: | llvm-readobj -s | FileCheck %s + +@data1 = global [4 x i32] [i32 1, i32 2, i32 3, i32 4], align 4 +@date2 = global [4 x i32] zeroinitializer, align 4 + +; CHECK: Name: .sdata +; CHECK-NEXT: Type: SHT_PROGBITS +; CHECK-NEXT: Flags [ (0x10000003) +; CHECK-NEXT: SHF_ALLOC +; CHECK-NEXT: SHF_MIPS_GPREL +; CHECK-NEXT: SHF_WRITE +; CHECK-NEXT: ] + +; CHECK: Name: .sbss +; CHECK-NEXT: Type: SHT_NOBITS +; CHECK-NEXT: Flags [ (0x10000003) +; CHECK-NEXT: SHF_ALLOC +; CHECK-NEXT: SHF_MIPS_GPREL +; CHECK-NEXT: SHF_WRITE +; CHECK-NEXT: ] -- 2.7.4