File tree Expand file tree Collapse file tree 4 files changed +42
-7
lines changed Expand file tree Collapse file tree 4 files changed +42
-7
lines changed Original file line number Diff line number Diff line change @@ -745,12 +745,18 @@ struct chpe_metadata {
745
745
support::ulittle32_t AuxiliaryIATCopy;
746
746
};
747
747
748
+ enum chpe_range_type { Arm64 = 0 , Arm64EC = 1 , Amd64 = 2 };
749
+
748
750
struct chpe_range_entry {
749
751
support::ulittle32_t StartOffset;
750
752
support::ulittle32_t Length;
751
- };
752
753
753
- enum chpe_range_type { CHPE_RANGE_ARM64, CHPE_RANGE_ARM64EC, CHPE_RANGE_AMD64 };
754
+ // The two low bits of StartOffset contain a range type.
755
+ static constexpr uint32_t TypeMask = 3 ;
756
+
757
+ uint32_t getStart () const { return StartOffset & ~TypeMask; }
758
+ uint16_t getType () const { return StartOffset & TypeMask; }
759
+ };
754
760
755
761
struct chpe_code_range_entry {
756
762
support::ulittle32_t StartRva;
Original file line number Diff line number Diff line change @@ -854,17 +854,17 @@ void COFFDumper::printCOFFLoadConfig() {
854
854
reportError (std::move (E), Obj->getFileName ());
855
855
auto CodeMap = reinterpret_cast <const chpe_range_entry *>(CodeMapInt);
856
856
for (uint32_t i = 0 ; i < CHPE->CodeMapCount ; i++) {
857
- uint32_t Start = CodeMap[i].StartOffset & ~ 3 ;
857
+ uint32_t Start = CodeMap[i].getStart () ;
858
858
W.startLine () << W.hex (Start) << " - "
859
859
<< W.hex (Start + CodeMap[i].Length ) << " " ;
860
- switch (CodeMap[i].StartOffset & 3 ) {
861
- case CHPE_RANGE_ARM64 :
860
+ switch (CodeMap[i].getType () ) {
861
+ case chpe_range_type::Arm64 :
862
862
W.getOStream () << " ARM64\n " ;
863
863
break ;
864
- case CHPE_RANGE_ARM64EC :
864
+ case chpe_range_type::Arm64EC :
865
865
W.getOStream () << " ARM64EC\n " ;
866
866
break ;
867
- case CHPE_RANGE_AMD64 :
867
+ case chpe_range_type::Amd64 :
868
868
W.getOStream () << " X64\n " ;
869
869
break ;
870
870
default :
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS
7
7
8
8
add_llvm_unittest (ObjectTests
9
9
ArchiveTest.cpp
10
+ COFFObjectFileTest.cpp
10
11
DXContainerTest.cpp
11
12
ELFObjectFileTest.cpp
12
13
ELFTypesTest.cpp
Original file line number Diff line number Diff line change
1
+ // ===- COFFObjectFileTest.cpp - Tests for COFFObjectFile ----------------===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ // ===----------------------------------------------------------------------===//
8
+
9
+ #include " llvm/Object/COFF.h"
10
+ #include " gtest/gtest.h"
11
+
12
+ using namespace llvm ::object;
13
+
14
+ TEST (COFFObjectFileTest, CHPERangeEntry) {
15
+ chpe_range_entry range;
16
+
17
+ range.StartOffset = 0x1000 ;
18
+ EXPECT_EQ (range.getStart (), 0x1000u );
19
+ EXPECT_EQ (range.getType (), chpe_range_type::Arm64);
20
+
21
+ range.StartOffset = 0x2000 | chpe_range_type::Arm64EC;
22
+ EXPECT_EQ (range.getStart (), 0x2000u );
23
+ EXPECT_EQ (range.getType (), chpe_range_type::Arm64EC);
24
+
25
+ range.StartOffset = 0x3000 | chpe_range_type::Amd64;
26
+ EXPECT_EQ (range.getStart (), 0x3000u );
27
+ EXPECT_EQ (range.getType (), chpe_range_type::Amd64);
28
+ }
You can’t perform that action at this time.
0 commit comments