brintos

brintos / llvm-project-archived public Read only

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