[PATCH] D150240: [RISCV] RISCVELFTargetObjectFile: use 2-byte alignment for .text if RVC
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 9 22:36:04 PDT 2023
MaskRay updated this revision to Diff 520907.
MaskRay added a comment.
Fix layer violation
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D150240/new/
https://reviews.llvm.org/D150240
Files:
llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCObjectFileInfo.cpp
llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCObjectFileInfo.h
llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp
llvm/lib/Target/RISCV/RISCVTargetObjectFile.h
llvm/test/CodeGen/RISCV/align.ll
Index: llvm/test/CodeGen/RISCV/align.ll
===================================================================
--- llvm/test/CodeGen/RISCV/align.ll
+++ llvm/test/CodeGen/RISCV/align.ll
@@ -2,6 +2,14 @@
; RUN: | FileCheck %s -check-prefix=RV32I
; RUN: llc -mtriple=riscv32 -mattr=+c -verify-machineinstrs < %s \
; RUN: | FileCheck %s -check-prefix=RV32C
+; RUN: llc -filetype=obj -mtriple=riscv32 < %s -o %t
+; RUN: llvm-readelf -S %t | FileCheck %s --check-prefixes=SEC,SEC-I
+; RUN: llc -filetype=obj -mtriple=riscv32 -mattr=+c < %s -o %t
+; RUN: llvm-readelf -S %t | FileCheck %s --check-prefixes=SEC,SEC-C
+
+; SEC: Name Type Address Off Size ES Flg Lk Inf Al
+; SEC-I: .text PROGBITS 00000000 [[#%x,]] [[#%x,]] 00 AX 0 0 4
+; SEC-C: .text PROGBITS 00000000 [[#%x,]] [[#%x,]] 00 AX 0 0 2
define void @foo() {
;RV32I: .p2align 2
Index: llvm/lib/Target/RISCV/RISCVTargetObjectFile.h
===================================================================
--- llvm/lib/Target/RISCV/RISCVTargetObjectFile.h
+++ llvm/lib/Target/RISCV/RISCVTargetObjectFile.h
@@ -20,6 +20,8 @@
unsigned SSThreshold = 8;
public:
+ unsigned getTextSectionAlignment() const override;
+
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
/// Return true if this global address should be placed into small data/bss
Index: llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp
+++ llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "RISCVTargetObjectFile.h"
+#include "MCTargetDesc/RISCVMCObjectFileInfo.h"
#include "RISCVTargetMachine.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/MC/MCContext.h"
@@ -14,6 +15,11 @@
using namespace llvm;
+unsigned RISCVELFTargetObjectFile::getTextSectionAlignment() const {
+ return RISCVMCObjectFileInfo::getTextSectionAlignment(
+ *getContext().getSubtargetInfo());
+}
+
void RISCVELFTargetObjectFile::Initialize(MCContext &Ctx,
const TargetMachine &TM) {
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCObjectFileInfo.h
===================================================================
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCObjectFileInfo.h
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCObjectFileInfo.h
@@ -14,11 +14,13 @@
#define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVMCOBJECTFILEINFO_H
#include "llvm/MC/MCObjectFileInfo.h"
+#include "llvm/MC/MCSubtargetInfo.h"
namespace llvm {
class RISCVMCObjectFileInfo : public MCObjectFileInfo {
public:
+ static unsigned getTextSectionAlignment(const MCSubtargetInfo &STI);
unsigned getTextSectionAlignment() const override;
};
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCObjectFileInfo.cpp
===================================================================
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCObjectFileInfo.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCObjectFileInfo.cpp
@@ -17,10 +17,13 @@
using namespace llvm;
+unsigned
+RISCVMCObjectFileInfo::getTextSectionAlignment(const MCSubtargetInfo &STI) {
+ bool RVC = STI.hasFeature(RISCV::FeatureStdExtC) ||
+ STI.hasFeature(RISCV::FeatureStdExtZca);
+ return RVC ? 2 : 4;
+}
+
unsigned RISCVMCObjectFileInfo::getTextSectionAlignment() const {
- const MCSubtargetInfo *STI = getContext().getSubtargetInfo();
- return (STI->hasFeature(RISCV::FeatureStdExtC) ||
- STI->hasFeature(RISCV::FeatureStdExtZca))
- ? 2
- : 4;
+ return getTextSectionAlignment(*getContext().getSubtargetInfo());
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150240.520907.patch
Type: text/x-patch
Size: 3804 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230510/874cf1c0/attachment.bin>
More information about the llvm-commits
mailing list