llvm.org GIT mirror llvm / 7a3698e
MC: adjust text section flags for WoA Correct the section flags for code built for Windows on ARM with `-ffunction-sections`. Windows on ARM uses solely Thumb-2 instructions, and indicates that the function is thumb by placing it in a text section that has IMAGE_SCN_MEM_16BIT flag set. When we encounter a .section directive, a new section is constructed. This may be a text segment. In order to identify that we need the additional flag, expose the target triple through the ObjectFileInfo as this information is lost otherwise. Since any modern ARM targeting environment on Windows would be Thumb-2 (Windows ARM NT or Windows Embedded Compact), introducing a new flag to indicate the section attribute seems to be a bit overkill. Simply depend on the target triple. Since there is one location that this information is currently needed, creating a target specific assembly parser and delegating the parsing of section switches also feels a bit heavy handed. If it turns out that this information ends up changing additional behaviour, then it may be worth considering that alternative. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211481 91177308-0d34-0410-b5e6-96231b3b80d8 Saleem Abdulrasool 6 years ago
4 changed file(s) with 78 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
1313 #ifndef LLVM_MC_MCBJECTFILEINFO_H
1414 #define LLVM_MC_MCBJECTFILEINFO_H
1515
16 #include "llvm/ADT/Triple.h"
1617 #include "llvm/Support/CodeGen.h"
1718
1819 namespace llvm {
1920 class MCContext;
2021 class MCSection;
2122 class StringRef;
22 class Triple;
2323
2424 class MCObjectFileInfo {
2525 protected:
379379 Reloc::Model RelocM;
380380 CodeModel::Model CMModel;
381381 MCContext *Ctx;
382 Triple TT;
382383
383384 void InitMachOMCObjectFileInfo(Triple T);
384385 void InitELFMCObjectFileInfo(Triple T);
387388 /// InitEHFrameSection - Initialize EHFrameSection on demand.
388389 ///
389390 void InitEHFrameSection();
391
392 public:
393 const Triple &getTargetTriple() const { return TT; }
390394 };
391395
392396 } // end namespace llvm
791791 SectionKind::getDataRel());
792792 }
793793
794 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
794 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef T, Reloc::Model relocm,
795795 CodeModel::Model cm,
796796 MCContext &ctx) {
797797 RelocM = relocm;
816816 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
817817 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
818818
819 Triple T(TT);
820 Triple::ArchType Arch = T.getArch();
819 TT = Triple(T);
820
821 Triple::ArchType Arch = TT.getArch();
821822 // FIXME: Checking for Arch here to filter out bogus triples such as
822823 // cellspu-apple-darwin. Perhaps we should fix in Triple?
823824 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
825826 Arch == Triple::arm64 || Arch == Triple::aarch64 ||
826827 Arch == Triple::ppc || Arch == Triple::ppc64 ||
827828 Arch == Triple::UnknownArch) &&
828 (T.isOSDarwin() || T.isOSBinFormatMachO())) {
829 (TT.isOSDarwin() || TT.isOSBinFormatMachO())) {
829830 Env = IsMachO;
830 InitMachOMCObjectFileInfo(T);
831 InitMachOMCObjectFileInfo(TT);
831832 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
832833 Arch == Triple::arm || Arch == Triple::thumb) &&
833 (T.isOSWindows() && T.getObjectFormat() == Triple::COFF)) {
834 (TT.isOSWindows() && TT.getObjectFormat() == Triple::COFF)) {
834835 Env = IsCOFF;
835 InitCOFFMCObjectFileInfo(T);
836 InitCOFFMCObjectFileInfo(TT);
836837 } else {
837838 Env = IsELF;
838 InitELFMCObjectFileInfo(T);
839 InitELFMCObjectFileInfo(TT);
839840 }
840841 }
841842
1212 #include "llvm/MC/MCAsmInfo.h"
1313 #include "llvm/MC/MCContext.h"
1414 #include "llvm/MC/MCExpr.h"
15 #include "llvm/MC/MCObjectFileInfo.h"
1516 #include "llvm/MC/MCParser/MCAsmLexer.h"
1617 #include "llvm/MC/MCRegisterInfo.h"
1718 #include "llvm/MC/MCSectionCOFF.h"
377378 return TokError("unexpected token in directive");
378379
379380 SectionKind Kind = computeSectionKind(Flags);
381 if (Kind.isText()) {
382 const Triple &T = getContext().getObjectFileInfo()->getTargetTriple();
383 if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
384 Flags |= COFF::IMAGE_SCN_MEM_16BIT;
385 }
380386 ParseSectionSwitch(SectionName, Flags, Kind, COMDATSymName, Type);
381387 return false;
382388 }
0 @ RUN: llvm-mc -triple thumbv7-windows-itanium -filetype obj -o - %s \
1 @ RUN: | llvm-readobj -s - | FileCheck %s
2
3 .syntax unified
4 .text
5 .thumb
6
7 .section .text,"xr",one_only,a
8
9 .def a;
10 .scl 2;
11 .type 32;
12 .endef
13 a:
14 movs r0, #65
15 bx lr
16
17 .section .text,"xr",one_only,b
18
19 .def b;
20 .scl 2;
21 .type 32;
22 .endef
23 .thumb_func
24 b:
25 movs r0, #66
26 bx lr
27
28 @ CHECK: Sections [
29 @ CHECK: Section {
30 @ CHECK: Name: .text
31 @ CHECK: Characteristics [
32 @ CHECK: IMAGE_SCN_CNT_CODE
33 @ CHECK: IMAGE_SCN_MEM_16BIT
34 @ CHECK: IMAGE_SCN_MEM_EXECUTE
35 @ CHECK: IMAGE_SCN_MEM_READ
36 @ CHECK: ]
37 @ CHECK: }
38 @ CHECK: Section {
39 @ CHECK: Name: .text
40 @ CHECK: Characteristics [
41 @ CHECK: IMAGE_SCN_CNT_CODE
42 @ CHECK: IMAGE_SCN_MEM_16BIT
43 @ CHECK: IMAGE_SCN_MEM_EXECUTE
44 @ CHECK: IMAGE_SCN_MEM_READ
45 @ CHECK: ]
46 @ CHECK: }
47 @ CHECK: Section {
48 @ CHECK: Name: .text
49 @ CHECK: Characteristics [
50 @ CHECK: IMAGE_SCN_CNT_CODE
51 @ CHECK: IMAGE_SCN_MEM_16BIT
52 @ CHECK: IMAGE_SCN_MEM_EXECUTE
53 @ CHECK: IMAGE_SCN_MEM_READ
54 @ CHECK: ]
55 @ CHECK: }
56 @ CHECK: ]
57