[llvm] 3e5f54d - Revert D139098 "[Alignment] Use Align for ObjectFile::getSectionAlignment"
Guillaume Chatelet via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 9 01:45:18 PST 2022
Author: Guillaume Chatelet
Date: 2022-12-09T09:45:04Z
New Revision: 3e5f54d6d710b1616a6467bfcd64c0d9e4f42af0
URL: https://github.com/llvm/llvm-project/commit/3e5f54d6d710b1616a6467bfcd64c0d9e4f42af0
DIFF: https://github.com/llvm/llvm-project/commit/3e5f54d6d710b1616a6467bfcd64c0d9e4f42af0.diff
LOG: Revert D139098 "[Alignment] Use Align for ObjectFile::getSectionAlignment"
This breaks lld.
This reverts commit 10c47465e2505ddfee4e62a2ab2e535abea3ec56.
Added:
Modified:
llvm/include/llvm/Object/COFF.h
llvm/include/llvm/Object/ELFObjectFile.h
llvm/include/llvm/Object/MachO.h
llvm/include/llvm/Object/ObjectFile.h
llvm/include/llvm/Object/Wasm.h
llvm/include/llvm/Object/XCOFFObjectFile.h
llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp
llvm/lib/Object/COFFObjectFile.cpp
llvm/lib/Object/MachOObjectFile.cpp
llvm/lib/Object/WasmObjectFile.cpp
llvm/lib/Object/XCOFFObjectFile.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Object/COFF.h b/llvm/include/llvm/Object/COFF.h
index 20faa54ec031c..8ad065d89c2a1 100644
--- a/llvm/include/llvm/Object/COFF.h
+++ b/llvm/include/llvm/Object/COFF.h
@@ -456,16 +456,18 @@ struct coff_section {
NumberOfRelocations == UINT16_MAX;
}
- Align getAlignment() const {
+ uint32_t getAlignment() const {
// The IMAGE_SCN_TYPE_NO_PAD bit is a legacy way of getting to
// IMAGE_SCN_ALIGN_1BYTES.
if (Characteristics & COFF::IMAGE_SCN_TYPE_NO_PAD)
- return Align(1);
+ return 1;
// Bit [20:24] contains section alignment. 0 means use a default alignment
// of 16.
- uint32_t EncodedLogValue = (Characteristics >> 20) & 0xF;
- return decodeMaybeAlign(EncodedLogValue).value_or(Align(16));
+ uint32_t Shift = (Characteristics >> 20) & 0xF;
+ if (Shift > 0)
+ return 1U << (Shift - 1);
+ return 16;
}
};
@@ -944,7 +946,7 @@ class COFFObjectFile : public ObjectFile {
uint64_t getSectionSize(DataRefImpl Sec) const override;
Expected<ArrayRef<uint8_t>>
getSectionContents(DataRefImpl Sec) const override;
- Align getSectionAlignment(DataRefImpl Sec) const override;
+ uint64_t getSectionAlignment(DataRefImpl Sec) const override;
bool isSectionCompressed(DataRefImpl Sec) const override;
bool isSectionText(DataRefImpl Sec) const override;
bool isSectionData(DataRefImpl Sec) const override;
diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h
index 5e90dc59c3caf..cbbec13f35c6c 100644
--- a/llvm/include/llvm/Object/ELFObjectFile.h
+++ b/llvm/include/llvm/Object/ELFObjectFile.h
@@ -294,7 +294,7 @@ template <class ELFT> class ELFObjectFile : public ELFObjectFileBase {
uint64_t getSectionSize(DataRefImpl Sec) const override;
Expected<ArrayRef<uint8_t>>
getSectionContents(DataRefImpl Sec) const override;
- Align getSectionAlignment(DataRefImpl Sec) const override;
+ uint64_t getSectionAlignment(DataRefImpl Sec) const override;
bool isSectionCompressed(DataRefImpl Sec) const override;
bool isSectionText(DataRefImpl Sec) const override;
bool isSectionData(DataRefImpl Sec) const override;
@@ -870,10 +870,8 @@ ELFObjectFile<ELFT>::getSectionContents(DataRefImpl Sec) const {
}
template <class ELFT>
-Align ELFObjectFile<ELFT>::getSectionAlignment(DataRefImpl Sec) const {
- // The value 0 or 1 means that the section has no alignment constraints.
- // https://man7.org/linux/man-pages/man5/elf.5.html
- return MaybeAlign(getSection(Sec)->sh_addralign).valueOrOne();
+uint64_t ELFObjectFile<ELFT>::getSectionAlignment(DataRefImpl Sec) const {
+ return getSection(Sec)->sh_addralign;
}
template <class ELFT>
diff --git a/llvm/include/llvm/Object/MachO.h b/llvm/include/llvm/Object/MachO.h
index 14dd8c21b0c53..00e2fc67013e5 100644
--- a/llvm/include/llvm/Object/MachO.h
+++ b/llvm/include/llvm/Object/MachO.h
@@ -446,7 +446,7 @@ class MachOObjectFile : public ObjectFile {
ArrayRef<uint8_t> getSectionContents(uint32_t Offset, uint64_t Size) const;
Expected<ArrayRef<uint8_t>>
getSectionContents(DataRefImpl Sec) const override;
- Align getSectionAlignment(DataRefImpl Sec) const override;
+ uint64_t getSectionAlignment(DataRefImpl Sec) const override;
Expected<SectionRef> getSection(unsigned SectionIndex) const;
Expected<SectionRef> getSection(StringRef SectionName) const;
bool isSectionCompressed(DataRefImpl Sec) const override;
diff --git a/llvm/include/llvm/Object/ObjectFile.h b/llvm/include/llvm/Object/ObjectFile.h
index 3921776895c98..c936ff8bf13d1 100644
--- a/llvm/include/llvm/Object/ObjectFile.h
+++ b/llvm/include/llvm/Object/ObjectFile.h
@@ -266,7 +266,7 @@ class ObjectFile : public SymbolicFile {
virtual uint64_t getSectionSize(DataRefImpl Sec) const = 0;
virtual Expected<ArrayRef<uint8_t>>
getSectionContents(DataRefImpl Sec) const = 0;
- virtual Align getSectionAlignment(DataRefImpl Sec) const = 0;
+ virtual uint64_t getSectionAlignment(DataRefImpl Sec) const = 0;
virtual bool isSectionCompressed(DataRefImpl Sec) const = 0;
virtual bool isSectionText(DataRefImpl Sec) const = 0;
virtual bool isSectionData(DataRefImpl Sec) const = 0;
@@ -482,7 +482,7 @@ inline Expected<StringRef> SectionRef::getContents() const {
}
inline uint64_t SectionRef::getAlignment() const {
- return OwningObject->getSectionAlignment(SectionPimpl).value();
+ return OwningObject->getSectionAlignment(SectionPimpl);
}
inline bool SectionRef::isCompressed() const {
diff --git a/llvm/include/llvm/Object/Wasm.h b/llvm/include/llvm/Object/Wasm.h
index faf94ed513a83..a26f703aeb43d 100644
--- a/llvm/include/llvm/Object/Wasm.h
+++ b/llvm/include/llvm/Object/Wasm.h
@@ -181,7 +181,7 @@ class WasmObjectFile : public ObjectFile {
uint64_t getSectionSize(DataRefImpl Sec) const override;
Expected<ArrayRef<uint8_t>>
getSectionContents(DataRefImpl Sec) const override;
- Align getSectionAlignment(DataRefImpl Sec) const override;
+ uint64_t getSectionAlignment(DataRefImpl Sec) const override;
bool isSectionCompressed(DataRefImpl Sec) const override;
bool isSectionText(DataRefImpl Sec) const override;
bool isSectionData(DataRefImpl Sec) const override;
diff --git a/llvm/include/llvm/Object/XCOFFObjectFile.h b/llvm/include/llvm/Object/XCOFFObjectFile.h
index 4efda9e361834..9ef94f4420b5a 100644
--- a/llvm/include/llvm/Object/XCOFFObjectFile.h
+++ b/llvm/include/llvm/Object/XCOFFObjectFile.h
@@ -581,7 +581,7 @@ class XCOFFObjectFile : public ObjectFile {
uint64_t getSectionSize(DataRefImpl Sec) const override;
Expected<ArrayRef<uint8_t>>
getSectionContents(DataRefImpl Sec) const override;
- Align getSectionAlignment(DataRefImpl Sec) const override;
+ uint64_t getSectionAlignment(DataRefImpl Sec) const override;
bool isSectionCompressed(DataRefImpl Sec) const override;
bool isSectionText(DataRefImpl Sec) const override;
bool isSectionData(DataRefImpl Sec) const override;
diff --git a/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp b/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp
index 23ab82e17257e..782928c260842 100644
--- a/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp
@@ -162,7 +162,7 @@ Error COFFLinkGraphBuilder::graphifySections() {
B = &G->createZeroFillBlock(
*GraphSec, getSectionSize(Obj, *Sec),
orc::ExecutorAddr(getSectionAddress(Obj, *Sec)),
- (*Sec)->getAlignment().value(), 0);
+ (*Sec)->getAlignment(), 0);
else {
ArrayRef<uint8_t> Data;
if (auto Err = Obj.getSectionContents(*Sec, Data))
@@ -178,7 +178,7 @@ Error COFFLinkGraphBuilder::graphifySections() {
B = &G->createContentBlock(
*GraphSec, CharData, orc::ExecutorAddr(getSectionAddress(Obj, *Sec)),
- (*Sec)->getAlignment().value(), 0);
+ (*Sec)->getAlignment(), 0);
}
setGraphBlock(SecIndex, B);
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp
index a74ff39986cb7..d0ca50e3506b3 100644
--- a/llvm/lib/Object/COFFObjectFile.cpp
+++ b/llvm/lib/Object/COFFObjectFile.cpp
@@ -299,9 +299,9 @@ COFFObjectFile::getSectionContents(DataRefImpl Ref) const {
return Res;
}
-Align COFFObjectFile::getSectionAlignment(DataRefImpl Ref) const {
+uint64_t COFFObjectFile::getSectionAlignment(DataRefImpl Ref) const {
const coff_section *Sec = toSec(Ref);
- return Align(Sec->getAlignment());
+ return Sec->getAlignment();
}
bool COFFObjectFile::isSectionCompressed(DataRefImpl Sec) const {
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp
index 7f90284c8747c..39e84fffcc4c6 100644
--- a/llvm/lib/Object/MachOObjectFile.cpp
+++ b/llvm/lib/Object/MachOObjectFile.cpp
@@ -1990,10 +1990,17 @@ MachOObjectFile::getSectionContents(DataRefImpl Sec) const {
return getSectionContents(Offset, Size);
}
-Align MachOObjectFile::getSectionAlignment(DataRefImpl Sec) const {
+uint64_t MachOObjectFile::getSectionAlignment(DataRefImpl Sec) const {
+ uint32_t Align;
+ if (is64Bit()) {
+ MachO::section_64 Sect = getSection64(Sec);
+ Align = Sect.align;
+ } else {
+ MachO::section Sect = getSection(Sec);
+ Align = Sect.align;
+ }
- return is64Bit() ? Align(1ULL << getSection64(Sec).align)
- : Align(1ULL << getSection(Sec).align);
+ return uint64_t(1) << Align;
}
Expected<SectionRef> MachOObjectFile::getSection(unsigned SectionIndex) const {
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index 6657102bf4797..0e24ac94bf70c 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -1735,8 +1735,8 @@ WasmObjectFile::getSectionContents(DataRefImpl Sec) const {
return S.Content;
}
-Align WasmObjectFile::getSectionAlignment(DataRefImpl Sec) const {
- return Align(1);
+uint64_t WasmObjectFile::getSectionAlignment(DataRefImpl Sec) const {
+ return 1;
}
bool WasmObjectFile::isSectionCompressed(DataRefImpl Sec) const {
diff --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp
index c6a571bcd8607..061c47d3eb56d 100644
--- a/llvm/lib/Object/XCOFFObjectFile.cpp
+++ b/llvm/lib/Object/XCOFFObjectFile.cpp
@@ -417,9 +417,10 @@ XCOFFObjectFile::getSectionContents(DataRefImpl Sec) const {
return makeArrayRef(ContentStart,SectionSize);
}
-Align XCOFFObjectFile::getSectionAlignment(DataRefImpl Sec) const {
+uint64_t XCOFFObjectFile::getSectionAlignment(DataRefImpl Sec) const {
+ uint64_t Result = 0;
llvm_unreachable("Not yet implemented!");
- return {};
+ return Result;
}
uint64_t XCOFFObjectFile::getSectionFileOffsetToRawData(DataRefImpl Sec) const {
More information about the llvm-commits
mailing list