llvm.org GIT mirror llvm / 0b8fc77
[llvm-objdump] Support detection of feature bits from the object and implement this for Mips. Summary: The Mips implementation only covers the feature bits described by the ELF e_flags so far. Mips stores additional feature bits such as MSA in the .MIPS.abiflags section. Also fixed a small bug this revealed where microMIPS wouldn't add the EF_MIPS_MICROMIPS flag when using -filetype=obj. Reviewers: echristo, rafael Subscribers: rafael, mehdi_amini, dsanders, sdardis, llvm-commits Differential Revision: http://reviews.llvm.org/D21125 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272880 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Sanders 3 years ago
23 changed file(s) with 122 addition(s) and 95 deletion(s). Raw diff Collapse all Expand all
767767 uint8_t getBytesInAddress() const override;
768768 StringRef getFileFormatName() const override;
769769 unsigned getArch() const override;
770 SubtargetFeatures getFeatures() const override { return SubtargetFeatures(); }
770771
771772 import_directory_iterator import_directory_begin() const;
772773 import_directory_iterator import_directory_end() const;
1818 #include "llvm/ADT/StringRef.h"
1919 #include "llvm/ADT/Triple.h"
2020 #include "llvm/ADT/iterator_range.h"
21 #include "llvm/MC/SubtargetFeature.h"
2122 #include "llvm/Object/Binary.h"
2223 #include "llvm/Object/ELF.h"
2324 #include "llvm/Object/ELFTypes.h"
5051 protected:
5152 ELFObjectFileBase(unsigned int Type, MemoryBufferRef Source);
5253
54 virtual uint16_t getEMachine() const = 0;
5355 virtual uint64_t getSymbolSize(DataRefImpl Symb) const = 0;
5456 virtual uint8_t getSymbolOther(DataRefImpl Symb) const = 0;
5557 virtual uint8_t getSymbolELFType(DataRefImpl Symb) const = 0;
6668 elf_symbol_iterator_range symbols() const;
6769
6870 static inline bool classof(const Binary *v) { return v->isELF(); }
71
72 SubtargetFeatures getFeatures() const override;
6973 };
7074
7175 class ELFSectionRef : public SectionRef {
178182 }
179183
180184 template class ELFObjectFile : public ELFObjectFileBase {
185 uint16_t getEMachine() const override;
181186 uint64_t getSymbolSize(DataRefImpl Sym) const override;
182187
183188 public:
424429 if (Sym->st_shndx == ELF::SHN_COMMON)
425430 return Sym->st_value;
426431 return 0;
432 }
433
434 template
435 uint16_t ELFObjectFile::getEMachine() const {
436 return EF.getHeader()->e_machine;
427437 }
428438
429439 template
261261
262262 StringRef getFileFormatName() const override;
263263 unsigned getArch() const override;
264 SubtargetFeatures getFeatures() const override { return SubtargetFeatures(); }
264265 Triple getArchTriple(const char **McpuDefault = nullptr) const;
265266
266267 relocation_iterator section_rel_begin(unsigned Index) const;
1414 #define LLVM_OBJECT_OBJECTFILE_H
1515
1616 #include "llvm/ADT/StringRef.h"
17 #include "llvm/MC/SubtargetFeature.h"
1718 #include "llvm/Object/SymbolicFile.h"
1819 #include "llvm/Support/DataTypes.h"
1920 #include "llvm/Support/ErrorHandling.h"
261262
262263 virtual StringRef getFileFormatName() const = 0;
263264 virtual /* Triple::ArchType */ unsigned getArch() const = 0;
265 virtual SubtargetFeatures getFeatures() const = 0;
264266
265267 /// Returns platform-specific object flags, if any.
266268 virtual std::error_code getPlatformFlags(unsigned &Result) const {
485485 EF_MIPS_ABI = 0x0000f000, // Mask for selecting EF_MIPS_ABI_ variant.
486486
487487 // MIPS machine variant
488 EF_MIPS_MACH_NONE = 0x00000000, // A standard MIPS implementation.
488489 EF_MIPS_MACH_3900 = 0x00810000, // Toshiba R3900
489490 EF_MIPS_MACH_4010 = 0x00820000, // LSI R4010
490491 EF_MIPS_MACH_4100 = 0x00830000, // NEC VR4100
5454 return std::move(R);
5555 }
5656
57 SubtargetFeatures ELFObjectFileBase::getFeatures() const {
58 switch (getEMachine()) {
59 case ELF::EM_MIPS: {
60 SubtargetFeatures Features;
61 unsigned PlatformFlags;
62 getPlatformFlags(PlatformFlags);
63
64 switch (PlatformFlags & ELF::EF_MIPS_ARCH) {
65 case ELF::EF_MIPS_ARCH_1:
66 break;
67 case ELF::EF_MIPS_ARCH_2:
68 Features.AddFeature("mips2");
69 break;
70 case ELF::EF_MIPS_ARCH_3:
71 Features.AddFeature("mips3");
72 break;
73 case ELF::EF_MIPS_ARCH_4:
74 Features.AddFeature("mips4");
75 break;
76 case ELF::EF_MIPS_ARCH_5:
77 Features.AddFeature("mips5");
78 break;
79 case ELF::EF_MIPS_ARCH_32:
80 Features.AddFeature("mips32");
81 break;
82 case ELF::EF_MIPS_ARCH_64:
83 Features.AddFeature("mips64");
84 break;
85 case ELF::EF_MIPS_ARCH_32R2:
86 Features.AddFeature("mips32r2");
87 break;
88 case ELF::EF_MIPS_ARCH_64R2:
89 Features.AddFeature("mips64r2");
90 break;
91 case ELF::EF_MIPS_ARCH_32R6:
92 Features.AddFeature("mips32r6");
93 break;
94 case ELF::EF_MIPS_ARCH_64R6:
95 Features.AddFeature("mips64r6");
96 break;
97 default:
98 llvm_unreachable("Unknown EF_MIPS_ARCH value");
99 }
100
101 switch (PlatformFlags & ELF::EF_MIPS_MACH) {
102 case ELF::EF_MIPS_MACH_NONE:
103 // No feature associated with this value.
104 break;
105 case ELF::EF_MIPS_MACH_OCTEON:
106 Features.AddFeature("cnmips");
107 break;
108 default:
109 llvm_unreachable("Unknown EF_MIPS_ARCH value");
110 }
111
112 if (PlatformFlags & ELF::EF_MIPS_ARCH_ASE_M16)
113 Features.AddFeature("mips16");
114 if (PlatformFlags & ELF::EF_MIPS_MICROMIPS)
115 Features.AddFeature("micromips");
116
117 return Features;
118 }
119 default:
120 return SubtargetFeatures();
121 }
122 }
123
57124 } // end namespace llvm
324324 if (Subtarget->isTargetNaCl())
325325 EmitAlignment(std::max(MF->getAlignment(), MIPS_NACL_BUNDLE_ALIGN));
326326
327 if (Subtarget->inMicroMipsMode())
327 if (Subtarget->inMicroMipsMode()) {
328328 TS.emitDirectiveSetMicroMips();
329 else
329 TS.setUsesMicroMips();
330 } else
330331 TS.emitDirectiveSetNoMicroMips();
331332
332333 if (Subtarget->inMips16Mode())
0 ; RUN: llc -march=mipsel -mcpu=mips32r2 -O0 -fast-isel=true -filetype=obj %s -o - \
1 ; RUN: | llvm-objdump -arch mipsel -mcpu=mips32r2 -d - | FileCheck %s
1 ; RUN: | llvm-objdump -d - | FileCheck %s
22
33 ; This test checks that encoding for srl is correct when fast-isel for mips32r2 is used.
44
0 ; RUN: llc -march=mipsel -mcpu=mips32r6 -disable-mips-delay-filler < %s | FileCheck %s
1 ; RUN: llc -march=mips -mcpu=mips32r6 -disable-mips-delay-filler < %s -filetype=obj -o - | llvm-objdump -arch=mips -mcpu=mips32r6 -d - | FileCheck %s -check-prefix=ENCODING
1 ; RUN: llc -march=mips -mcpu=mips32r6 -disable-mips-delay-filler < %s \
2 ; RUN: -filetype=obj -o - | llvm-objdump -d - | FileCheck %s -check-prefix=ENCODING
23
34 ; bnezc and beqzc have restriction that $rt != 0
45
0 ; RUN: llc -march=mipsel -filetype=obj --disable-machine-licm -mattr=micromips < %s -o - \
1 ; RUN: | llvm-objdump -no-show-raw-insn -arch mipsel -mcpu=mips32r2 -mattr=micromips -d - \
2 ; RUN: | FileCheck %s -check-prefix=MICROMIPS
1 ; RUN: | llvm-objdump -no-show-raw-insn -d - | FileCheck %s -check-prefix=MICROMIPS
32
43 ; Use llvm-objdump to check wheter the encodings of microMIPS atomic instructions are correct.
54 ; While emitting assembly files directly when in microMIPS mode, it is possible to emit a mips32r2
0 # RUN: llvm-mc %s -arch=mips -mcpu=mips32r2 | FileCheck %s -check-prefix=ASM
11 #
2 # RUN: llvm-mc %s -arch=mips -mcpu=mips32r2 -mattr=+o32 -filetype=obj -o -| \
3 # RUN: llvm-objdump -d -r -arch=mips - | \
4 # RUN: FileCheck %s -check-prefix=OBJ-O32
2 # RUN: llvm-mc %s -arch=mips -mcpu=mips32r2 -filetype=obj -o -| \
3 # RUN: llvm-objdump -d -r - | FileCheck %s -check-prefix=OBJ-O32
54
65 # RUN: llvm-mc %s -arch=mips64 -mcpu=mips64r2 -target-abi n32 -filetype=obj -o -| \
7 # RUN: llvm-objdump -d -r -arch=mips - | \
8 # RUN: FileCheck %s -check-prefix=OBJ-N32
6 # RUN: llvm-objdump -d -r - | FileCheck %s -check-prefix=OBJ-N32
97
10 # RUN: llvm-mc %s -arch=mips64 -mcpu=mips64r2 -mattr=+n64 -filetype=obj -o -| \
11 # RUN: llvm-objdump -d -r -arch=mips - | \
12 # RUN: FileCheck %s -check-prefix=OBJ-N64
8 # RUN: llvm-mc %s -arch=mips64 -mcpu=mips64r2 -filetype=obj -o -| \
9 # RUN: llvm-objdump -d -r - | FileCheck %s -check-prefix=OBJ-N64
1310
1411 # ASM: .text
1512 # ASM: .option pic2
1111 # RUN: FileCheck %s -check-prefix=NO-STORE
1212
1313 # RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -filetype=obj -o - | \
14 # RUN: llvm-objdump -d -r - | \
15 # RUN: FileCheck %s -check-prefix=NO-STORE
14 # RUN: llvm-objdump -d -r - | FileCheck %s -check-prefix=NO-STORE
1615
1716 .text
1817 .ent foo
11 # RUN: FileCheck %s
22
33 # RUN: llvm-mc %s -arch=mips -mcpu=mips32 --position-independent -filetype=obj -o -| \
4 # RUN: llvm-objdump -d -r -arch=mips - | \
5 # RUN: FileCheck %s -check-prefix=CHECK-FOR-STORE
4 # RUN: llvm-objdump -d -r - | FileCheck %s -check-prefix=CHECK-FOR-STORE
65
76 # RUN: llvm-mc %s -arch=mips -mcpu=mips32 -mattr=+micromips --position-independent -show-encoding | \
87 # RUN: FileCheck %s -check-prefix=MICROMIPS
11 # RUN: FileCheck %s
22
33 # RUN: llvm-mc %s -arch=mips -mcpu=mips32 --position-independent -filetype=obj -o -| \
4 # RUN: llvm-objdump -d -r -arch=mips - | \
5 # RUN: FileCheck %s -check-prefix=CHECK-FOR-STORE
4 # RUN: llvm-objdump -d -r - | FileCheck %s -check-prefix=CHECK-FOR-STORE
65
76 # RUN: llvm-mc %s -arch=mips -mcpu=mips32 -mattr=+micromips --position-independent -show-encoding | \
87 # RUN: FileCheck %s -check-prefix=MICROMIPS
None # RUN: llvm-mc -triple mips64-unknown-unknown -target-abi o32 -filetype=obj -o - %s | \
1 # RUN: llvm-objdump -d -r -arch=mips64 - | \
2 # RUN: FileCheck -check-prefix=ALL -check-prefix=O32 %s
0 # RUN: llvm-mc -triple mips64-unknown-linux -target-abi o32 -filetype=obj -o - %s | \
1 # RUN: llvm-objdump -d -r - | FileCheck -check-prefix=ALL -check-prefix=O32 %s
32
43 # RUN: llvm-mc -triple mips64-unknown-unknown -target-abi o32 %s | \
54 # RUN: FileCheck -check-prefix=ALL -check-prefix=ASM %s
65
7 # RUN: llvm-mc -triple mips64-unknown-unknown -target-abi n32 -filetype=obj -o - %s | \
8 # RUN: llvm-objdump -d -r -arch=mips64 - | \
9 # RUN: FileCheck -check-prefix=ALL -check-prefix=NXX -check-prefix=N32 %s
6 # RUN: llvm-mc -triple mips64-unknown-linux -target-abi n32 -filetype=obj -o - %s | \
7 # RUN: llvm-objdump -d -r - | \
8 # RUN: FileCheck -check-prefix=ALL -check-prefix=NXX -check-prefix=N32 %s
109
1110 # RUN: llvm-mc -triple mips64-unknown-unknown -target-abi n32 %s | \
1211 # RUN: FileCheck -check-prefix=ALL -check-prefix=ASM %s
1312
14 # RUN: llvm-mc -triple mips64-unknown-unknown %s -filetype=obj -o - | \
15 # RUN: llvm-objdump -d -r -arch=mips64 - | \
16 # RUN: FileCheck -check-prefix=ALL -check-prefix=NXX -check-prefix=N64 %s
13 # RUN: llvm-mc -triple mips64-unknown-linux %s -filetype=obj -o - | \
14 # RUN: llvm-objdump -d -r - | \
15 # RUN: FileCheck -check-prefix=ALL -check-prefix=NXX -check-prefix=N64 %s
1716
1817 # RUN: llvm-mc -triple mips64-unknown-unknown %s | \
1918 # RUN: FileCheck -check-prefix=ALL -check-prefix=ASM %s
0 # RUN: llvm-mc %s -triple=mipsel-unknown-linux -mcpu=mips32r2 \
11 # RUN: -mattr=+micromips 2>&1 -filetype=obj > %t.o
2 # RUN: llvm-objdump %t.o -mattr=+micromips -d | FileCheck %s
2 # RUN: llvm-objdump %t.o -d | FileCheck %s
33
44 # Check that fixup data is written in the microMIPS specific little endian
55 # byte order.
+0
-56
test/MC/Mips/mips64extins.ll less more
None ; RUN: llc -march=mips64el -filetype=obj -mcpu=mips64r2 -target-abi=n64 %s -o - \
1 ; RUN: | llvm-objdump -disassemble -mattr +mips64r2 - | FileCheck %s
2
3 define i64 @dext(i64 %i) nounwind readnone {
4 entry:
5 ; CHECK: dext ${{[0-9]+}}, ${{[0-9]+}}, 5, 10
6 %shr = lshr i64 %i, 5
7 %and = and i64 %shr, 1023
8 ret i64 %and
9 }
10
11 define i64 @dextu(i64 %i) nounwind readnone {
12 entry:
13 ; CHECK: dextu ${{[0-9]+}}, ${{[0-9]+}}, 34, 6
14 %shr = lshr i64 %i, 34
15 %and = and i64 %shr, 63
16 ret i64 %and
17 }
18
19 define i64 @dextm(i64 %i) nounwind readnone {
20 entry:
21 ; CHECK: dextm ${{[0-9]+}}, ${{[0-9]+}}, 5, 34
22 %shr = lshr i64 %i, 5
23 %and = and i64 %shr, 17179869183
24 ret i64 %and
25 }
26
27 define i64 @dins(i64 %i, i64 %j) nounwind readnone {
28 entry:
29 ; CHECK: dins ${{[0-9]+}}, ${{[0-9]+}}, 8, 10
30 %shl2 = shl i64 %j, 8
31 %and = and i64 %shl2, 261888
32 %and3 = and i64 %i, -261889
33 %or = or i64 %and3, %and
34 ret i64 %or
35 }
36
37 define i64 @dinsm(i64 %i, i64 %j) nounwind readnone {
38 entry:
39 ; CHECK: dinsm ${{[0-9]+}}, ${{[0-9]+}}, 10, 1
40 %shl4 = shl i64 %j, 10
41 %and = and i64 %shl4, 8796093021184
42 %and5 = and i64 %i, -8796093021185
43 %or = or i64 %and5, %and
44 ret i64 %or
45 }
46
47 define i64 @dinsu(i64 %i, i64 %j) nounwind readnone {
48 entry:
49 ; CHECK: dinsu ${{[0-9]+}}, ${{[0-9]+}}, 40, 13
50 %shl4 = shl i64 %j, 40
51 %and = and i64 %shl4, 9006099743113216
52 %and5 = and i64 %i, -9006099743113217
53 %or = or i64 %and5, %and
54 ret i64 %or
55 }
0 # RUN: llvm-mc -arch=mips64el -filetype=obj -mcpu=mips64r2 -target-abi=n64 %s -o - \
1 # RUN: | llvm-objdump -disassemble - | FileCheck %s
2
3 dext $2, $4, 5, 10 # CHECK: dext ${{[0-9]+}}, ${{[0-9]+}}, 5, 10
4 dextu $2, $4, 34, 6 # CHECK: dextu ${{[0-9]+}}, ${{[0-9]+}}, 34, 6
5 dextm $2, $4, 5, 34 # CHECK: dextm ${{[0-9]+}}, ${{[0-9]+}}, 5, 34
6 dins $4, $5, 8, 10 # CHECK: dins ${{[0-9]+}}, ${{[0-9]+}}, 8, 10
7 dinsm $4, $5, 10, 1 # CHECK: dinsm ${{[0-9]+}}, ${{[0-9]+}}, 10, 1
8 dinsu $4, $5, 40, 13 # CHECK: dinsu ${{[0-9]+}}, ${{[0-9]+}}, 40, 13
33 // field.
44
55 // RUN: llvm-mc -mcpu=mips32r2 -triple=mipsel-pc-linux -filetype=obj %s -o - \
6 // RUN: | llvm-objdump -disassemble -mattr +mips32r2 - \
7 // RUN: | FileCheck %s
6 // RUN: | llvm-objdump -disassemble - | FileCheck %s
87 // RUN: llvm-mc -mcpu=mips32r2 -triple=mips-pc-linux -filetype=obj %s -o - \
9 // RUN: | llvm-objdump -disassemble -mattr +mips32r2 - \
10 // RUN: | FileCheck %s
8 // RUN: | llvm-objdump -disassemble - | FileCheck %s
119
1210 .text
1311 .abicalls
0 # RUN: llvm-mc %s -arch=mips -mcpu=mips32 -filetype=obj -o - | \
1 # RUN: llvm-objdump -d -r -arch=mips - | FileCheck %s
1 # RUN: llvm-objdump -d -r - | FileCheck %s
22
33 .global foo
44 .weak bar
0 RUN: llvm-objdump -disassemble %p/../Inputs/dext-test.elf-mips64r2 | FileCheck %s
1 RUN: llvm-objdump -disassemble -mattr +mips64r2 %p/../Inputs/dext-test.elf-mips64r2 \
12 RUN: | FileCheck %s
23
0 RUN: llvm-objdump -d %p/../Inputs/micro-mips.elf-mipsel | FileCheck %s
1 RUN: llvm-objdump -d -mattr=micromips %p/../Inputs/micro-mips.elf-mipsel \
12 RUN: | FileCheck %s
23
930930 const Target *TheTarget = getTarget(Obj);
931931
932932 // Package up features to be passed to target/subtarget
933 std::string FeaturesStr;
933 SubtargetFeatures Features = Obj->getFeatures();
934934 if (MAttrs.size()) {
935 SubtargetFeatures Features;
936935 for (unsigned i = 0; i != MAttrs.size(); ++i)
937936 Features.AddFeature(MAttrs[i]);
938 FeaturesStr = Features.getString();
939937 }
940938
941939 std::unique_ptr MRI(
949947 if (!AsmInfo)
950948 report_fatal_error("error: no assembly info for target " + TripleName);
951949 std::unique_ptr STI(
952 TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr));
950 TheTarget->createMCSubtargetInfo(TripleName, MCPU, Features.getString()));
953951 if (!STI)
954952 report_fatal_error("error: no subtarget info for target " + TripleName);
955953 std::unique_ptr MII(TheTarget->createMCInstrInfo());