diff --git a/lld/test/ELF/arm-thumb-branch.s b/lld/test/ELF/arm-thumb-branch.s --- a/lld/test/ELF/arm-thumb-branch.s +++ b/lld/test/ELF/arm-thumb-branch.s @@ -59,7 +59,6 @@ /// far_cond = 0x110023 // CHECK-NEXT: 10020: 3f f3 ff af bgt.w 0x110022 // CHECK-NEXT: 10024: 70 47 bx lr -// CHECK-NEXT: 10026: // CHECK-EMPTY: // CHECK-NEXT: Disassembly of section .callee2: // CHECK-EMPTY: diff --git a/lld/test/ELF/arm-thunk-linkerscript-orphan.s b/lld/test/ELF/arm-thunk-linkerscript-orphan.s --- a/lld/test/ELF/arm-thunk-linkerscript-orphan.s +++ b/lld/test/ELF/arm-thunk-linkerscript-orphan.s @@ -29,7 +29,7 @@ // CHECK-NEXT: 100010: c0 f2 00 2c movt r12, #512 // CHECK-NEXT: 100014: 60 47 bx r12 // CHECK: <__Thumbv7ABSLongThunk_orphan_target>: -// CHECK-NEXT: 100016: 40 f2 15 0c movw r12, #21 +// CHECK-NEXT: 100016: 40 f2 13 0c movw r12, #19 // CHECK-NEXT: 10001a: c0 f2 00 2c movt r12, #512 // CHECK-NEXT: 10001e: 60 47 bx r12 .section .text_high, "ax", %progbits @@ -43,7 +43,7 @@ // CHECK-EMPTY: // CHECK-NEXT: : // CHECK-NEXT: 2000000: 00 f0 02 f8 bl 0x2000008 <__Thumbv7ABSLongThunk_low_target> -// CHECK-NEXT: 2000004: 00 f0 06 f8 bl 0x2000014 +// CHECK-NEXT: 2000004: 00 f0 05 f8 bl 0x2000012 // CHECK: <__Thumbv7ABSLongThunk_low_target>: // CHECK-NEXT: 2000008: 40 f2 03 0c movw r12, #3 // CHECK-NEXT: 200000c: c0 f2 10 0c movt r12, #16 @@ -59,8 +59,8 @@ // CHECK: Disassembly of section orphan: // CHECK-EMPTY: // CHECK-NEXT: : -// CHECK-NEXT: 2000014: ff f7 f8 ff bl 0x2000008 <__Thumbv7ABSLongThunk_low_target> -// CHECK-NEXT: 2000018: ff f7 f2 ff bl 0x2000000 +// CHECK-NEXT: 2000012: ff f7 f9 ff bl 0x2000008 <__Thumbv7ABSLongThunk_low_target> +// CHECK-NEXT: 2000016: ff f7 f3 ff bl 0x2000000 .data .word 10 diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCObjectFileInfo.h b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCObjectFileInfo.h new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCObjectFileInfo.h @@ -0,0 +1,27 @@ +//===-- ARMMCObjectFileInfo.h - ARM object file Info -------*- C++ -*--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file contains the declaration of the ARMMCObjectFileInfo class. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_ARM_MCTARGETDESC_ARMMCOBJECTFILEINFO_H +#define LLVM_LIB_TARGET_ARM_MCTARGETDESC_ARMMCOBJECTFILEINFO_H + +#include "llvm/MC/MCObjectFileInfo.h" + +namespace llvm { + +class ARMMCObjectFileInfo : public MCObjectFileInfo { +public: + unsigned getTextSectionAlignment() const override; +}; + +} // namespace llvm + +#endif diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCObjectFileInfo.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCObjectFileInfo.cpp new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCObjectFileInfo.cpp @@ -0,0 +1,20 @@ +//===-- ARMMCObjectFileInfo.cpp - ARM object file properties ----------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file contains the declarations of the ARMMCObjectFileInfo properties. +// +//===----------------------------------------------------------------------===// + +#include "ARMMCObjectFileInfo.h" +#include "llvm/MC/MCContext.h" + +using namespace llvm; + +unsigned ARMMCObjectFileInfo::getTextSectionAlignment() const { + return getContext().getTargetTriple().isThumb() ? 2 : 4; +} diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp @@ -15,6 +15,7 @@ #include "ARMBaseInfo.h" #include "ARMInstPrinter.h" #include "ARMMCAsmInfo.h" +#include "ARMMCObjectFileInfo.h" #include "TargetInfo/ARMTargetInfo.h" #include "llvm/ADT/Triple.h" #include "llvm/DebugInfo/CodeView/CodeView.h" @@ -650,6 +651,14 @@ return STI.getFeatureBits()[ARM::FeatureCoprocCDE0 + Coproc]; } +static MCObjectFileInfo * +createARMMCObjectFileInfo(MCContext &Ctx, bool PIC, + bool LargeCodeModel = false) { + MCObjectFileInfo *MOFI = new ARMMCObjectFileInfo(); + MOFI->initMCObjectFileInfo(Ctx, PIC, LargeCodeModel); + return MOFI; +} + // Force static initialization. extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARMTargetMC() { for (Target *T : {&getTheARMLETarget(), &getTheARMBETarget(), @@ -686,6 +695,9 @@ // Register the MC relocation info. TargetRegistry::RegisterMCRelocationInfo(*T, createARMMCRelocationInfo); + + // Register the MCObjectFileInfo. + TargetRegistry::RegisterMCObjectFileInfo(*T, createARMMCObjectFileInfo); } // Register the MC instruction analyzer. diff --git a/llvm/lib/Target/ARM/MCTargetDesc/CMakeLists.txt b/llvm/lib/Target/ARM/MCTargetDesc/CMakeLists.txt --- a/llvm/lib/Target/ARM/MCTargetDesc/CMakeLists.txt +++ b/llvm/lib/Target/ARM/MCTargetDesc/CMakeLists.txt @@ -3,12 +3,13 @@ ARMELFObjectWriter.cpp ARMELFStreamer.cpp ARMInstPrinter.cpp - ARMMachObjectWriter.cpp - ARMMachORelocationInfo.cpp ARMMCAsmInfo.cpp ARMMCCodeEmitter.cpp ARMMCExpr.cpp + ARMMCObjectFileInfo.cpp ARMMCTargetDesc.cpp + ARMMachORelocationInfo.cpp + ARMMachObjectWriter.cpp ARMTargetStreamer.cpp ARMUnwindOpAsm.cpp ARMWinCOFFObjectWriter.cpp diff --git a/llvm/test/CodeGen/ARM/thumb-text-align.s b/llvm/test/CodeGen/ARM/thumb-text-align.s new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/ARM/thumb-text-align.s @@ -0,0 +1,20 @@ +// RUN: llvm-mc < %s -triple=thumbv7-linux-gnueabi -filetype=obj -o - \ +// RUN: | llvm-readobj -S --sd - | FileCheck %s --check-prefixes=CHECK,CHECK-THUMB +// RUN: llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o - \ +// RUN: | llvm-readobj -S --sd - | FileCheck %s --check-prefixes=CHECK,CHECK-ARM +mov pc, lr + +// CHECK: Name: .text (1) +// CHECK-NEXT: Type: SHT_PROGBITS (0x1) +// CHECK-NEXT: Flags [ (0x6) +// CHECK-NEXT: SHF_ALLOC (0x2) +// CHECK-NEXT: SHF_EXECINSTR (0x4) +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x0 +// CHECK-NEXT: Offset: 0x34 +// CHECK-THUMB-NEXT: Size: 2 +// CHECK-ARM-NEXT: Size: 4 +// CHECK-NEXT: Link: 0 +// CHECK-NEXT: Info: 0 +// CHECK-THUMB-NEXT: AddressAlignment: 2 +// CHECK-ARM-NEXT: AddressAlignment: 4 diff --git a/llvm/utils/gn/secondary/llvm/lib/Target/ARM/MCTargetDesc/BUILD.gn b/llvm/utils/gn/secondary/llvm/lib/Target/ARM/MCTargetDesc/BUILD.gn --- a/llvm/utils/gn/secondary/llvm/lib/Target/ARM/MCTargetDesc/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/lib/Target/ARM/MCTargetDesc/BUILD.gn @@ -66,6 +66,7 @@ "ARMMCAsmInfo.cpp", "ARMMCCodeEmitter.cpp", "ARMMCExpr.cpp", + "ARMMCObjectFileInfo.cpp", "ARMMCTargetDesc.cpp", "ARMMachORelocationInfo.cpp", "ARMMachObjectWriter.cpp",