[Lldb-commits] [PATCH] D157059: [lldb][PECOFF] Exclude alignment padding when reading section data

2023-08-03 Thread Hiroshi Yamauchi via Phabricator via lldb-commits
hjyamauchi created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
hjyamauchi requested review of this revision.
Herald added projects: LLDB, LLVM.
Herald added subscribers: llvm-commits, lldb-commits.

There can be zero padding bytes at a section end for file alignment in PECOFF. 
Exclude those padding bytes when reading the section data.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157059

Files:
  lldb/include/lldb/Symbol/ObjectFile.h
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
  lldb/source/Symbol/ObjectFile.cpp
  lldb/unittests/ObjectFile/PECOFF/CMakeLists.txt
  lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp
  llvm/lib/ObjectYAML/COFFYAML.cpp
  llvm/test/tools/yaml2obj/COFF/invalid-raw-data.yaml
  llvm/test/tools/yaml2obj/COFF/xrelocs.yaml

Index: llvm/test/tools/yaml2obj/COFF/xrelocs.yaml
===
--- llvm/test/tools/yaml2obj/COFF/xrelocs.yaml
+++ llvm/test/tools/yaml2obj/COFF/xrelocs.yaml
@@ -30,6 +30,7 @@
 # CHECK-YAML-NEXT: Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_NRELOC_OVFL, IMAGE_SCN_MEM_READ ]
 # CHECK-YAML-NEXT: Alignment:   16
 # CHECK-YAML-NEXT: SectionData: ''
+# CHECK-YAML-NEXT: SizeOfRawData:   16
 # CHECK-YAML-NEXT: Relocations:
 # CHECK-YAML-NEXT:   - VirtualAddress:  0
 # CHECK-YAML-NEXT: SymbolName:  foo
Index: llvm/test/tools/yaml2obj/COFF/invalid-raw-data.yaml
===
--- llvm/test/tools/yaml2obj/COFF/invalid-raw-data.yaml
+++ llvm/test/tools/yaml2obj/COFF/invalid-raw-data.yaml
@@ -1,5 +1,5 @@
 # RUN: not yaml2obj %s -o %t 2>&1 | FileCheck %s
-# CHECK: YAML:18:5: error: unknown key 'SizeOfRawData'
+# CHECK: YAML:14:5: error: StructuredData and SizeOfRawData can't be used together
 
 --- !COFF
 OptionalHeader:
Index: llvm/lib/ObjectYAML/COFFYAML.cpp
===
--- llvm/lib/ObjectYAML/COFFYAML.cpp
+++ llvm/lib/ObjectYAML/COFFYAML.cpp
@@ -689,11 +689,12 @@
 return;
   }
 
-  // Uninitialized sections, such as .bss, typically have no data, but the size
-  // is carried in SizeOfRawData, even though PointerToRawData is zero.
-  if (Sec.SectionData.binary_size() == 0 && Sec.StructuredData.empty() &&
-  NC->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
-IO.mapOptional("SizeOfRawData", Sec.Header.SizeOfRawData);
+  IO.mapOptional("SizeOfRawData", Sec.Header.SizeOfRawData, 0U);
+
+  if (!Sec.StructuredData.empty() && Sec.Header.SizeOfRawData) {
+IO.setError("StructuredData and SizeOfRawData can't be used together");
+return;
+  }
 
   IO.mapOptional("Relocations", Sec.Relocations);
 }
Index: lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp
===
--- /dev/null
+++ lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp
@@ -0,0 +1,78 @@
+//===-- TestSectionFileSize.cpp ---===//
+//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "gtest/gtest.h"
+
+#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
+#include "Plugins/Process/Utility/lldb-x86-register-enums.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+
+#include "lldb/Core/Module.h"
+#include "lldb/Symbol/CallFrameInfo.h"
+#include "lldb/Symbol/UnwindPlan.h"
+#include "llvm/Testing/Support/Error.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+class SectionSizeTest : public testing::Test {
+  SubsystemRAII subsystems;
+};
+
+TEST_F(SectionSizeTest, NoAlignmentPadding) {
+  llvm::Expected ExpectedFile = TestFile::fromYaml(
+  R"(
+--- !COFF
+OptionalHeader:
+  SectionAlignment: 4096
+  FileAlignment:   512
+header:
+  Machine: IMAGE_FILE_MACHINE_AMD64
+  Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE ]
+sections:
+  - Name:swiftast
+VirtualSize: 496
+SizeOfRawData:   512
+Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
+SectionData: 
+
+symbols: []
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSP module_sp = std::make_shared(ExpectedFile->moduleSpec());
+  ObjectFile *object_file = module_sp->GetObjectFile();
+  ASSERT_NE(object_file, nullptr);
+
+  SectionList *section_list = object_file->GetSectionList();
+  ASSERT_NE(sec

[Lldb-commits] [PATCH] D157059: [lldb][PECOFF] Exclude alignment padding when reading section data

2023-08-03 Thread Hiroshi Yamauchi via Phabricator via lldb-commits
hjyamauchi updated this revision to Diff 547086.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157059/new/

https://reviews.llvm.org/D157059

Files:
  lldb/include/lldb/Symbol/ObjectFile.h
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
  lldb/source/Symbol/ObjectFile.cpp
  lldb/unittests/ObjectFile/PECOFF/CMakeLists.txt
  lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp
  llvm/lib/ObjectYAML/COFFYAML.cpp
  llvm/test/tools/yaml2obj/COFF/invalid-raw-data.yaml
  llvm/test/tools/yaml2obj/COFF/xrelocs.yaml

Index: llvm/test/tools/yaml2obj/COFF/xrelocs.yaml
===
--- llvm/test/tools/yaml2obj/COFF/xrelocs.yaml
+++ llvm/test/tools/yaml2obj/COFF/xrelocs.yaml
@@ -30,6 +30,7 @@
 # CHECK-YAML-NEXT: Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_NRELOC_OVFL, IMAGE_SCN_MEM_READ ]
 # CHECK-YAML-NEXT: Alignment:   16
 # CHECK-YAML-NEXT: SectionData: ''
+# CHECK-YAML-NEXT: SizeOfRawData:   16
 # CHECK-YAML-NEXT: Relocations:
 # CHECK-YAML-NEXT:   - VirtualAddress:  0
 # CHECK-YAML-NEXT: SymbolName:  foo
Index: llvm/test/tools/yaml2obj/COFF/invalid-raw-data.yaml
===
--- llvm/test/tools/yaml2obj/COFF/invalid-raw-data.yaml
+++ llvm/test/tools/yaml2obj/COFF/invalid-raw-data.yaml
@@ -1,5 +1,5 @@
 # RUN: not yaml2obj %s -o %t 2>&1 | FileCheck %s
-# CHECK: YAML:18:5: error: unknown key 'SizeOfRawData'
+# CHECK: YAML:14:5: error: StructuredData and SizeOfRawData can't be used together
 
 --- !COFF
 OptionalHeader:
Index: llvm/lib/ObjectYAML/COFFYAML.cpp
===
--- llvm/lib/ObjectYAML/COFFYAML.cpp
+++ llvm/lib/ObjectYAML/COFFYAML.cpp
@@ -689,11 +689,12 @@
 return;
   }
 
-  // Uninitialized sections, such as .bss, typically have no data, but the size
-  // is carried in SizeOfRawData, even though PointerToRawData is zero.
-  if (Sec.SectionData.binary_size() == 0 && Sec.StructuredData.empty() &&
-  NC->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
-IO.mapOptional("SizeOfRawData", Sec.Header.SizeOfRawData);
+  IO.mapOptional("SizeOfRawData", Sec.Header.SizeOfRawData, 0U);
+
+  if (!Sec.StructuredData.empty() && Sec.Header.SizeOfRawData) {
+IO.setError("StructuredData and SizeOfRawData can't be used together");
+return;
+  }
 
   IO.mapOptional("Relocations", Sec.Relocations);
 }
Index: lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp
===
--- /dev/null
+++ lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp
@@ -0,0 +1,78 @@
+//===-- TestSectionFileSize.cpp ---===//
+//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "gtest/gtest.h"
+
+#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
+#include "Plugins/Process/Utility/lldb-x86-register-enums.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+
+#include "lldb/Core/Module.h"
+#include "lldb/Symbol/CallFrameInfo.h"
+#include "lldb/Symbol/UnwindPlan.h"
+#include "llvm/Testing/Support/Error.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+class SectionSizeTest : public testing::Test {
+  SubsystemRAII subsystems;
+};
+
+TEST_F(SectionSizeTest, NoAlignmentPadding) {
+  llvm::Expected ExpectedFile = TestFile::fromYaml(
+  R"(
+--- !COFF
+OptionalHeader:
+  SectionAlignment: 4096
+  FileAlignment:   512
+header:
+  Machine: IMAGE_FILE_MACHINE_AMD64
+  Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE ]
+sections:
+  - Name:swiftast
+VirtualSize: 496
+SizeOfRawData:   512
+Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
+SectionData: 
+
+symbols: []
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSP module_sp = std::make_shared(ExpectedFile->moduleSpec());
+  ObjectFile *object_file = module_sp->GetObjectFile();
+  ASSERT_NE(object_file, nullptr);
+
+  SectionList *section_list = object_file->GetSectionList();
+  ASSERT_NE(section_list, nullptr);
+
+  SectionSP swiftast_section;
+  size_t section_count = section_list->GetNumSections(0);
+  for (size_t i = 0; i < section_count; ++i) {
+SectionSP section_sp = section_list->GetSectionAtIndex(i);
+if (section_sp->GetName() == "swiftast") {
+  swiftast_section = s

[Lldb-commits] [PATCH] D157059: [lldb][PECOFF] Exclude alignment padding when reading section data

2023-08-04 Thread Hiroshi Yamauchi via Phabricator via lldb-commits
hjyamauchi updated this revision to Diff 547272.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157059/new/

https://reviews.llvm.org/D157059

Files:
  lldb/include/lldb/Symbol/ObjectFile.h
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
  lldb/source/Symbol/ObjectFile.cpp
  lldb/unittests/ObjectFile/PECOFF/CMakeLists.txt
  lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp
  llvm/lib/ObjectYAML/COFFYAML.cpp
  llvm/test/tools/yaml2obj/COFF/invalid-raw-data.yaml
  llvm/test/tools/yaml2obj/COFF/xrelocs.yaml

Index: llvm/test/tools/yaml2obj/COFF/xrelocs.yaml
===
--- llvm/test/tools/yaml2obj/COFF/xrelocs.yaml
+++ llvm/test/tools/yaml2obj/COFF/xrelocs.yaml
@@ -30,6 +30,7 @@
 # CHECK-YAML-NEXT: Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_NRELOC_OVFL, IMAGE_SCN_MEM_READ ]
 # CHECK-YAML-NEXT: Alignment:   16
 # CHECK-YAML-NEXT: SectionData: ''
+# CHECK-YAML-NEXT: SizeOfRawData:   16
 # CHECK-YAML-NEXT: Relocations:
 # CHECK-YAML-NEXT:   - VirtualAddress:  0
 # CHECK-YAML-NEXT: SymbolName:  foo
Index: llvm/test/tools/yaml2obj/COFF/invalid-raw-data.yaml
===
--- llvm/test/tools/yaml2obj/COFF/invalid-raw-data.yaml
+++ llvm/test/tools/yaml2obj/COFF/invalid-raw-data.yaml
@@ -1,5 +1,5 @@
 # RUN: not yaml2obj %s -o %t 2>&1 | FileCheck %s
-# CHECK: YAML:18:5: error: unknown key 'SizeOfRawData'
+# CHECK: YAML:14:5: error: StructuredData and SizeOfRawData can't be used together
 
 --- !COFF
 OptionalHeader:
Index: llvm/lib/ObjectYAML/COFFYAML.cpp
===
--- llvm/lib/ObjectYAML/COFFYAML.cpp
+++ llvm/lib/ObjectYAML/COFFYAML.cpp
@@ -689,11 +689,12 @@
 return;
   }
 
-  // Uninitialized sections, such as .bss, typically have no data, but the size
-  // is carried in SizeOfRawData, even though PointerToRawData is zero.
-  if (Sec.SectionData.binary_size() == 0 && Sec.StructuredData.empty() &&
-  NC->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
-IO.mapOptional("SizeOfRawData", Sec.Header.SizeOfRawData);
+  IO.mapOptional("SizeOfRawData", Sec.Header.SizeOfRawData, 0U);
+
+  if (!Sec.StructuredData.empty() && Sec.Header.SizeOfRawData) {
+IO.setError("StructuredData and SizeOfRawData can't be used together");
+return;
+  }
 
   IO.mapOptional("Relocations", Sec.Relocations);
 }
Index: lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp
===
--- /dev/null
+++ lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp
@@ -0,0 +1,78 @@
+//===-- TestSectionFileSize.cpp ---===//
+//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "gtest/gtest.h"
+
+#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
+#include "Plugins/Process/Utility/lldb-x86-register-enums.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+
+#include "lldb/Core/Module.h"
+#include "lldb/Symbol/CallFrameInfo.h"
+#include "lldb/Symbol/UnwindPlan.h"
+#include "llvm/Testing/Support/Error.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+class SectionSizeTest : public testing::Test {
+  SubsystemRAII subsystems;
+};
+
+TEST_F(SectionSizeTest, NoAlignmentPadding) {
+  llvm::Expected ExpectedFile = TestFile::fromYaml(
+  R"(
+--- !COFF
+OptionalHeader:
+  SectionAlignment: 4096
+  FileAlignment:   512
+header:
+  Machine: IMAGE_FILE_MACHINE_AMD64
+  Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE ]
+sections:
+  - Name:swiftast
+VirtualSize: 496
+SizeOfRawData:   512
+Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
+SectionData: 
+
+symbols: []
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSP module_sp = std::make_shared(ExpectedFile->moduleSpec());
+  ObjectFile *object_file = module_sp->GetObjectFile();
+  ASSERT_NE(object_file, nullptr);
+
+  SectionList *section_list = object_file->GetSectionList();
+  ASSERT_NE(section_list, nullptr);
+
+  SectionSP swiftast_section;
+  size_t section_count = section_list->GetNumSections(0);
+  for (size_t i = 0; i < section_count; ++i) {
+SectionSP section_sp = section_list->GetSectionAtIndex(i);
+if (section_sp->GetName() == "swiftast") {
+  swiftast_section = s

[Lldb-commits] [PATCH] D157059: [lldb][PECOFF] Exclude alignment padding when reading section data

2023-08-04 Thread Hiroshi Yamauchi via Phabricator via lldb-commits
hjyamauchi marked an inline comment as done.
hjyamauchi added inline comments.



Comment at: lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp:1035
+  // llvm::object::COFFObjectFile::getSectionSize().
+  if (m_binary->getDOSHeader())
+return std::min(section->GetByteSize(), section->GetFileSize());

compnerd wrote:
> Can we use `m_binary->getPEHeader() || m_binary->getPE32Header()` here 
> instead?  We are technically ensuring that this is a linked (PE) binary 
> rather than an object file.  While a DOS header is present, it is not an 
> absolute requirement (theoretically, it is practically never going to change).
Done.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157059/new/

https://reviews.llvm.org/D157059

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D157059: [lldb][PECOFF] Exclude alignment padding when reading section data

2023-08-04 Thread Hiroshi Yamauchi via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
hjyamauchi marked an inline comment as done.
Closed by commit rGe9040e875d92: [lldb][PECOFF] Exclude alignment padding when 
reading section data (authored by hjyamauchi).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157059/new/

https://reviews.llvm.org/D157059

Files:
  lldb/include/lldb/Symbol/ObjectFile.h
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
  lldb/source/Symbol/ObjectFile.cpp
  lldb/unittests/ObjectFile/PECOFF/CMakeLists.txt
  lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp
  llvm/lib/ObjectYAML/COFFYAML.cpp
  llvm/test/tools/yaml2obj/COFF/invalid-raw-data.yaml
  llvm/test/tools/yaml2obj/COFF/xrelocs.yaml

Index: llvm/test/tools/yaml2obj/COFF/xrelocs.yaml
===
--- llvm/test/tools/yaml2obj/COFF/xrelocs.yaml
+++ llvm/test/tools/yaml2obj/COFF/xrelocs.yaml
@@ -30,6 +30,7 @@
 # CHECK-YAML-NEXT: Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_NRELOC_OVFL, IMAGE_SCN_MEM_READ ]
 # CHECK-YAML-NEXT: Alignment:   16
 # CHECK-YAML-NEXT: SectionData: ''
+# CHECK-YAML-NEXT: SizeOfRawData:   16
 # CHECK-YAML-NEXT: Relocations:
 # CHECK-YAML-NEXT:   - VirtualAddress:  0
 # CHECK-YAML-NEXT: SymbolName:  foo
Index: llvm/test/tools/yaml2obj/COFF/invalid-raw-data.yaml
===
--- llvm/test/tools/yaml2obj/COFF/invalid-raw-data.yaml
+++ llvm/test/tools/yaml2obj/COFF/invalid-raw-data.yaml
@@ -1,5 +1,5 @@
 # RUN: not yaml2obj %s -o %t 2>&1 | FileCheck %s
-# CHECK: YAML:18:5: error: unknown key 'SizeOfRawData'
+# CHECK: YAML:14:5: error: StructuredData and SizeOfRawData can't be used together
 
 --- !COFF
 OptionalHeader:
Index: llvm/lib/ObjectYAML/COFFYAML.cpp
===
--- llvm/lib/ObjectYAML/COFFYAML.cpp
+++ llvm/lib/ObjectYAML/COFFYAML.cpp
@@ -689,11 +689,12 @@
 return;
   }
 
-  // Uninitialized sections, such as .bss, typically have no data, but the size
-  // is carried in SizeOfRawData, even though PointerToRawData is zero.
-  if (Sec.SectionData.binary_size() == 0 && Sec.StructuredData.empty() &&
-  NC->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
-IO.mapOptional("SizeOfRawData", Sec.Header.SizeOfRawData);
+  IO.mapOptional("SizeOfRawData", Sec.Header.SizeOfRawData, 0U);
+
+  if (!Sec.StructuredData.empty() && Sec.Header.SizeOfRawData) {
+IO.setError("StructuredData and SizeOfRawData can't be used together");
+return;
+  }
 
   IO.mapOptional("Relocations", Sec.Relocations);
 }
Index: lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp
===
--- /dev/null
+++ lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp
@@ -0,0 +1,78 @@
+//===-- TestSectionFileSize.cpp ---===//
+//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "gtest/gtest.h"
+
+#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
+#include "Plugins/Process/Utility/lldb-x86-register-enums.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+
+#include "lldb/Core/Module.h"
+#include "lldb/Symbol/CallFrameInfo.h"
+#include "lldb/Symbol/UnwindPlan.h"
+#include "llvm/Testing/Support/Error.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+class SectionSizeTest : public testing::Test {
+  SubsystemRAII subsystems;
+};
+
+TEST_F(SectionSizeTest, NoAlignmentPadding) {
+  llvm::Expected ExpectedFile = TestFile::fromYaml(
+  R"(
+--- !COFF
+OptionalHeader:
+  SectionAlignment: 4096
+  FileAlignment:   512
+header:
+  Machine: IMAGE_FILE_MACHINE_AMD64
+  Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE ]
+sections:
+  - Name:swiftast
+VirtualSize: 496
+SizeOfRawData:   512
+Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
+SectionData: 
+
+symbols: []
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSP module_sp = std::make_shared(ExpectedFile->moduleSpec());
+  ObjectFile *object_file = module_sp->GetObjectFile();
+  ASSERT_NE(object_file, nullptr);
+
+  SectionList *section_list = object_file->GetSectionList();
+  ASSERT_NE(section_lis

[Lldb-commits] [PATCH] D157059: [lldb][PECOFF] Exclude alignment padding when reading section data

2023-08-16 Thread Hiroshi Yamauchi via Phabricator via lldb-commits
hjyamauchi added a comment.

In D157059#4572809 , @Michael137 
wrote:

> Hi, this is failing on swift-ci (runs on x86 bots) with the following error:
>
>   
> /Users/ec2-user/jenkins/workspace/oss-lldb-incremental-macos-cmake/build/Ninja-ReleaseAssert+stdlib-Release/lldb-macosx-x86_64/unittests/ObjectFile/PECOFF/./ObjectFilePECOFFTests
>  --gtest_filter=SectionSizeTest.NoAlignmentPadding
>   --
>   YAML:12:5: error: unknown key 'SizeOfRawData'
>   SizeOfRawData:   512
>   ^
>   
> /Users/ec2-user/jenkins/workspace/oss-lldb-incremental-macos-cmake/llvm-project/lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp:49:
>  Failure
>   Value of: llvm::detail::TakeExpected(ExpectedFile)
>   Expected: succeeded
> Actual: failed  (convertYAML() failed)
>   
>   
> /Users/ec2-user/jenkins/workspace/oss-lldb-incremental-macos-cmake/llvm-project/lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp:49
>   Value of: llvm::detail::TakeExpected(ExpectedFile)
>   Expected: succeeded
> Actual: failed  (convertYAML() failed)
>
> https://ci.swift.org/view/LLDB/job/oss-lldb-incremental-macos-cmake/
>
> Could you take a look please?

Fix: https://github.com/apple/llvm-project/pull/7218


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157059/new/

https://reviews.llvm.org/D157059

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits