From 23025c812e8f9d7c4fef90c3499c4686e0669db0 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Tue, 14 Apr 2015 18:53:03 +0000 Subject: [PATCH] [Mips] Write _DYNAMIC symbol on MIPS targets llvm-svn: 234925 --- .../ReaderWriter/ELF/Mips/MipsELFWriters.h | 8 ++++ lld/test/elf/Mips/dynamic-sym.test | 41 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 lld/test/elf/Mips/dynamic-sym.test diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsELFWriters.h b/lld/lib/ReaderWriter/ELF/Mips/MipsELFWriters.h index ed21e42a95f1..854e82ef51b9 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsELFWriters.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsELFWriters.h @@ -16,6 +16,13 @@ namespace elf { template class MipsTargetLayout; +class MipsDynamicAtom : public DynamicAtom { +public: + MipsDynamicAtom(const File &f) : DynamicAtom(f) {} + + ContentPermissions permissions() const override { return permR__; } +}; + template class MipsELFWriter { public: MipsELFWriter(MipsLinkingContext &ctx, MipsTargetLayout &targetLayout) @@ -54,6 +61,7 @@ public: file->addAbsoluteAtom("_gp"); file->addAbsoluteAtom("_gp_disp"); file->addAbsoluteAtom("__gnu_local_gp"); + file->addAtom(*new (file->allocator()) MipsDynamicAtom(*file)); } return file; } diff --git a/lld/test/elf/Mips/dynamic-sym.test b/lld/test/elf/Mips/dynamic-sym.test new file mode 100644 index 000000000000..818ef04ad4f5 --- /dev/null +++ b/lld/test/elf/Mips/dynamic-sym.test @@ -0,0 +1,41 @@ +# Check _DYNAMIC symbol's value +# +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -shared -e T0 -o %t.so %t.o +# RUN: llvm-objdump -h -t %t.so | FileCheck -check-prefix=SHARED %s + +# SHARED: Sections: +# SHARED: Idx Name Size Address Type +# SHARED: 5 .dynamic 00000068 00000000000000d4 + +# SHARED: SYMBOL TABLE: +# SHARED: 000000d4 g .dynamic 00000000 _DYNAMIC + +# RUN: lld -flavor gnu -target mipsel -e main -e T0 -o %t.exe %t.o +# RUN: llvm-objdump -h -t %t.exe | FileCheck -check-prefix=EXE %s + +# EXE: Sections: +# EXE: Idx Name Size Address Type +# EXE: 6 .dynamic 00000068 0000000000400114 + +# EXE: SYMBOL TABLE: +# EXE: 00400114 g .dynamic 00000000 _DYNAMIC + +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [SHF_ALLOC, SHF_EXECINSTR] + AddressAlign: 0x10 + Size: 0x04 + +Symbols: + Global: + - Name: T0 + Section: .text