Delete machine_type.h/cpp
It didn't make sense to be burning a whole TU for one function.
Also unwrap "DllInfo" and "LibInfo" structs that were not providing value.
MODIFY
include/vcpkg/base/cofffilereader.h
include/vcpkg/base/cofffilereader.h
#pragma once
#include <vcpkg/base/files.h>
-#include <vcpkg/base/machinetype.h>
+
+#include <stdint.h>
#include <vector>
-namespace vcpkg::CoffFileReader
+namespace vcpkg
{
- struct DllInfo
+ enum class MachineType : uint16_t
{
- MachineType machine_type;
+ UNKNOWN = 0x0, // The contents of this field are assumed to be applicable to any machine type
+ AM33 = 0x1d3, // Matsushita AM33
+ AMD64 = 0x8664, // x64
+ ARM = 0x1c0, // ARM little endian
+ ARM64 = 0xaa64, // ARM64 little endian
+ ARMNT = 0x1c4, // ARM Thumb-2 little endian
+ EBC = 0xebc, // EFI byte code
+ I386 = 0x14c, // Intel 386 or later processors and compatible processors
+ IA64 = 0x200, // Intel Itanium processor family
+ M32R = 0x9041, // Mitsubishi M32R little endian
+ MIPS16 = 0x266, // MIPS16
+ MIPSFPU = 0x366, // MIPS with FPU
+ MIPSFPU16 = 0x466, // MIPS16 with FPU
+ POWERPC = 0x1f0, // Power PC little endian
+ POWERPCFP = 0x1f1, // Power PC with floating point support
+ R4000 = 0x166, // MIPS little endian
+ RISCV32 = 0x5032, // RISC-V 32-bit address space
+ RISCV64 = 0x5064, // RISC-V 64-bit address space
+ RISCV128 = 0x5128, // RISC-V 128-bit address space
+ SH3 = 0x1a2, // Hitachi SH3
+ SH3DSP = 0x1a3, // Hitachi SH3 DSP
+ SH4 = 0x1a6, // Hitachi SH4
+ SH5 = 0x1a8, // Hitachi SH5
+ THUMB = 0x1c2, // Thumb
+ WCEMIPSV2 = 0x169, // MIPS little-endian WCE v2
};
- struct LibInfo
- {
- std::vector<MachineType> machine_types;
- };
+ MachineType to_machine_type(const uint16_t value);
- DllInfo read_dll(const ReadFilePointer& fs);
+ MachineType read_dll_machine_type(const ReadFilePointer& fs);
- LibInfo read_lib(const ReadFilePointer& fs);
+ std::vector<MachineType> read_lib_machine_types(const ReadFilePointer& fs);
}

DELETE
include/vcpkg/base/machinetype.h
-#pragma once
-
-#include <cstdint>
-
-namespace vcpkg
-{
- enum class MachineType : uint16_t
- {
- UNKNOWN = 0x0, // The contents of this field are assumed to be applicable to any machine type
- AM33 = 0x1d3, // Matsushita AM33
- AMD64 = 0x8664, // x64
- ARM = 0x1c0, // ARM little endian
- ARM64 = 0xaa64, // ARM64 little endian
- ARMNT = 0x1c4, // ARM Thumb-2 little endian
- EBC = 0xebc, // EFI byte code
- I386 = 0x14c, // Intel 386 or later processors and compatible processors
- IA64 = 0x200, // Intel Itanium processor family
- M32R = 0x9041, // Mitsubishi M32R little endian
- MIPS16 = 0x266, // MIPS16
- MIPSFPU = 0x366, // MIPS with FPU
- MIPSFPU16 = 0x466, // MIPS16 with FPU
- POWERPC = 0x1f0, // Power PC little endian
- POWERPCFP = 0x1f1, // Power PC with floating point support
- R4000 = 0x166, // MIPS little endian
- RISCV32 = 0x5032, // RISC-V 32-bit address space
- RISCV64 = 0x5064, // RISC-V 64-bit address space
- RISCV128 = 0x5128, // RISC-V 128-bit address space
- SH3 = 0x1a2, // Hitachi SH3
- SH3DSP = 0x1a3, // Hitachi SH3 DSP
- SH4 = 0x1a6, // Hitachi SH4
- SH5 = 0x1a8, // Hitachi SH5
- THUMB = 0x1c2, // Thumb
- WCEMIPSV2 = 0x169, // MIPS little-endian WCE v2
- };
-
- MachineType to_machine_type(const uint16_t value);
-}

MODIFY
src/vcpkg/base/cofffilereader.cpp
src/vcpkg/base/cofffilereader.cpp
@@ -10,7 +10,7 @@ using namespace std;
// See https://docs.microsoft.com/en-us/windows/win32/debug/pe-format
-namespace vcpkg::CoffFileReader
+namespace vcpkg
{
static void read_and_verify_pe_signature(const ReadFilePointer& fs)
{
@@ -43,12 +43,12 @@ namespace vcpkg::CoffFileReader
static_assert(sizeof(CoffFileHeader) == 20, "The CoffFileHeader struct must match its on-disk representation");
- DllInfo read_dll(const ReadFilePointer& fs)
+ MachineType read_dll_machine_type(const ReadFilePointer& fs)
{
read_and_verify_pe_signature(fs);
CoffFileHeader header;
Checks::check_exit(VCPKG_LINE_INFO, fs.read(&header, sizeof(header), 1) == 1);
- return {to_machine_type(header.machine)};
+ return to_machine_type(header.machine);
}
struct ArchiveMemberHeader
@@ -193,11 +193,45 @@ namespace vcpkg::CoffFileReader
return machine_types;
}
- LibInfo read_lib(const ReadFilePointer& fs)
+ std::vector<MachineType> read_lib_machine_types(const ReadFilePointer& fs)
{
read_and_verify_archive_file_signature(fs);
read_and_skip_first_linker_member(fs);
const auto offsets = read_second_linker_member_offsets(fs);
- return {read_machine_types_from_archive_members(fs, offsets)};
+ return read_machine_types_from_archive_members(fs, offsets);
+ }
+
+ MachineType to_machine_type(const uint16_t value)
+ {
+ const MachineType t = static_cast<MachineType>(value);
+ switch (t)
+ {
+ case MachineType::UNKNOWN:
+ case MachineType::AM33:
+ case MachineType::AMD64:
+ case MachineType::ARM:
+ case MachineType::ARM64:
+ case MachineType::ARMNT:
+ case MachineType::EBC:
+ case MachineType::I386:
+ case MachineType::IA64:
+ case MachineType::M32R:
+ case MachineType::MIPS16:
+ case MachineType::MIPSFPU:
+ case MachineType::MIPSFPU16:
+ case MachineType::POWERPC:
+ case MachineType::POWERPCFP:
+ case MachineType::R4000:
+ case MachineType::RISCV32:
+ case MachineType::RISCV64:
+ case MachineType::RISCV128:
+ case MachineType::SH3:
+ case MachineType::SH3DSP:
+ case MachineType::SH4:
+ case MachineType::SH5:
+ case MachineType::THUMB:
+ case MachineType::WCEMIPSV2: return t;
+ default: Checks::exit_maybe_upgrade(VCPKG_LINE_INFO, "Unknown machine type code 0x%hx", value);
+ }
}
}

DELETE
src/vcpkg/base/machinetype.cpp
-#include <vcpkg/base/checks.h>
-#include <vcpkg/base/machinetype.h>
-
-namespace vcpkg
-{
- MachineType to_machine_type(const uint16_t value)
- {
- const MachineType t = static_cast<MachineType>(value);
- switch (t)
- {
- case MachineType::UNKNOWN:
- case MachineType::AM33:
- case MachineType::AMD64:
- case MachineType::ARM:
- case MachineType::ARM64:
- case MachineType::ARMNT:
- case MachineType::EBC:
- case MachineType::I386:
- case MachineType::IA64:
- case MachineType::M32R:
- case MachineType::MIPS16:
- case MachineType::MIPSFPU:
- case MachineType::MIPSFPU16:
- case MachineType::POWERPC:
- case MachineType::POWERPCFP:
- case MachineType::R4000:
- case MachineType::RISCV32:
- case MachineType::RISCV64:
- case MachineType::RISCV128:
- case MachineType::SH3:
- case MachineType::SH3DSP:
- case MachineType::SH4:
- case MachineType::SH5:
- case MachineType::THUMB:
- case MachineType::WCEMIPSV2: return t;
- default: Checks::exit_maybe_upgrade(VCPKG_LINE_INFO, "Unknown machine type code 0x%hx", value);
- }
- }
-}

MODIFY
src/vcpkg/postbuildlint.cpp
src/vcpkg/postbuildlint.cpp
@@ -537,8 +537,8 @@ namespace vcpkg::PostBuildLint
file.extension() == dot_dll,
"The file extension was not .dll: %s",
generic_u8string(file));
- const CoffFileReader::DllInfo info = CoffFileReader::read_dll(fs.open_for_read(VCPKG_LINE_INFO, file));
- const std::string actual_architecture = get_actual_architecture(info.machine_type);
+ const auto machine_type = read_dll_machine_type(fs.open_for_read(VCPKG_LINE_INFO, file));
+ const std::string actual_architecture = get_actual_architecture(machine_type);
if (expected_architecture != actual_architecture)
{
@@ -570,18 +570,18 @@ namespace vcpkg::PostBuildLint
file.extension() == dot_lib,
"The file extension was not .lib: %s",
generic_u8string(file));
- CoffFileReader::LibInfo info = CoffFileReader::read_lib(fs.open_for_read(VCPKG_LINE_INFO, file));
+ const auto machine_types = read_lib_machine_types(fs.open_for_read(VCPKG_LINE_INFO, file));
// This is zero for folly's debug library
// TODO: Why?
- if (info.machine_types.size() == 0) return LintStatus::SUCCESS;
+ if (machine_types.empty()) return LintStatus::SUCCESS;
Checks::check_exit(VCPKG_LINE_INFO,
- info.machine_types.size() == 1,
+ machine_types.size() == 1,
"Found more than 1 architecture in file %s",
generic_u8string(file));
- const std::string actual_architecture = get_actual_architecture(info.machine_types.at(0));
+ const std::string actual_architecture = get_actual_architecture(machine_types.front());
if (expected_architecture != actual_architecture)
{
binaries_with_invalid_architecture.push_back({file, actual_architecture});

Delete machine_type.h/cpp (#120)

It didn't make sense to be burning a whole TU for one function.

Also unwrap "DllInfo" and "LibInfo" structs that were not providing value.