1e9040e87SHiroshi Yamauchi //===-- TestSectionFileSize.cpp -------------------------------------------===//
2e9040e87SHiroshi Yamauchi //
3e9040e87SHiroshi Yamauchi //
4e9040e87SHiroshi Yamauchi // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5e9040e87SHiroshi Yamauchi // See https://llvm.org/LICENSE.txt for license information.
6e9040e87SHiroshi Yamauchi // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7e9040e87SHiroshi Yamauchi //
8e9040e87SHiroshi Yamauchi //===----------------------------------------------------------------------===//
9e9040e87SHiroshi Yamauchi
10e9040e87SHiroshi Yamauchi #include "gtest/gtest.h"
11e9040e87SHiroshi Yamauchi
12e9040e87SHiroshi Yamauchi #include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
13e9040e87SHiroshi Yamauchi #include "Plugins/Process/Utility/lldb-x86-register-enums.h"
14e9040e87SHiroshi Yamauchi #include "TestingSupport/SubsystemRAII.h"
15e9040e87SHiroshi Yamauchi #include "TestingSupport/TestUtilities.h"
16e9040e87SHiroshi Yamauchi
17e9040e87SHiroshi Yamauchi #include "lldb/Core/Module.h"
18e9040e87SHiroshi Yamauchi #include "lldb/Symbol/CallFrameInfo.h"
19e9040e87SHiroshi Yamauchi #include "lldb/Symbol/UnwindPlan.h"
20e9040e87SHiroshi Yamauchi #include "llvm/Testing/Support/Error.h"
21e9040e87SHiroshi Yamauchi
22e9040e87SHiroshi Yamauchi using namespace lldb_private;
23e9040e87SHiroshi Yamauchi using namespace lldb;
24e9040e87SHiroshi Yamauchi
25e9040e87SHiroshi Yamauchi class SectionSizeTest : public testing::Test {
26e9040e87SHiroshi Yamauchi SubsystemRAII<FileSystem, ObjectFilePECOFF> subsystems;
27e9040e87SHiroshi Yamauchi };
28e9040e87SHiroshi Yamauchi
TEST_F(SectionSizeTest,NoAlignmentPadding)29e9040e87SHiroshi Yamauchi TEST_F(SectionSizeTest, NoAlignmentPadding) {
30e9040e87SHiroshi Yamauchi llvm::Expected<TestFile> ExpectedFile = TestFile::fromYaml(
31e9040e87SHiroshi Yamauchi R"(
32e9040e87SHiroshi Yamauchi --- !COFF
33e9040e87SHiroshi Yamauchi OptionalHeader:
34e9040e87SHiroshi Yamauchi SectionAlignment: 4096
35e9040e87SHiroshi Yamauchi FileAlignment: 512
36e9040e87SHiroshi Yamauchi header:
37e9040e87SHiroshi Yamauchi Machine: IMAGE_FILE_MACHINE_AMD64
38e9040e87SHiroshi Yamauchi Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE ]
39e9040e87SHiroshi Yamauchi sections:
40e9040e87SHiroshi Yamauchi - Name: swiftast
41e9040e87SHiroshi Yamauchi VirtualSize: 496
42e9040e87SHiroshi Yamauchi SizeOfRawData: 512
43e9040e87SHiroshi Yamauchi Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
44e9040e87SHiroshi Yamauchi SectionData: 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000
45e9040e87SHiroshi Yamauchi
46e9040e87SHiroshi Yamauchi symbols: []
47e9040e87SHiroshi Yamauchi ...
48e9040e87SHiroshi Yamauchi )");
49e9040e87SHiroshi Yamauchi ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
50e9040e87SHiroshi Yamauchi
51e9040e87SHiroshi Yamauchi ModuleSP module_sp = std::make_shared<Module>(ExpectedFile->moduleSpec());
52e9040e87SHiroshi Yamauchi ObjectFile *object_file = module_sp->GetObjectFile();
53e9040e87SHiroshi Yamauchi ASSERT_NE(object_file, nullptr);
54e9040e87SHiroshi Yamauchi
55e9040e87SHiroshi Yamauchi SectionList *section_list = object_file->GetSectionList();
56e9040e87SHiroshi Yamauchi ASSERT_NE(section_list, nullptr);
57e9040e87SHiroshi Yamauchi
58e9040e87SHiroshi Yamauchi SectionSP swiftast_section;
59e9040e87SHiroshi Yamauchi size_t section_count = section_list->GetNumSections(0);
60e9040e87SHiroshi Yamauchi for (size_t i = 0; i < section_count; ++i) {
61e9040e87SHiroshi Yamauchi SectionSP section_sp = section_list->GetSectionAtIndex(i);
62e9040e87SHiroshi Yamauchi if (section_sp->GetName() == "swiftast") {
63e9040e87SHiroshi Yamauchi swiftast_section = section_sp;
64e9040e87SHiroshi Yamauchi break;
65e9040e87SHiroshi Yamauchi }
66e9040e87SHiroshi Yamauchi }
67e9040e87SHiroshi Yamauchi ASSERT_NE(swiftast_section.get(), nullptr);
68e9040e87SHiroshi Yamauchi
69e9040e87SHiroshi Yamauchi DataExtractor section_data;
70e9040e87SHiroshi Yamauchi ASSERT_NE(object_file->ReadSectionData(swiftast_section.get(),
71e9040e87SHiroshi Yamauchi section_data),
72*a330759dSJie Fu (size_t)0);
73e9040e87SHiroshi Yamauchi
74e9040e87SHiroshi Yamauchi // Check that the section data size is equal to VirtualSize (496)
75e9040e87SHiroshi Yamauchi // without the zero padding, instead of SizeOfRawData (512).
76*a330759dSJie Fu EXPECT_EQ(section_data.GetByteSize(), (uint64_t)496);
77e9040e87SHiroshi Yamauchi }
78e9040e87SHiroshi Yamauchi
79