commit
bba5c8a39a
109 files changed
+14085
No files matched your search
@@ -0,0 +1,46 @@
|
||||
#include "writer.hpp"
|
||||
|
||||
#include "format/vlc_format.hpp"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace voidlibc::voidlink {
|
||||
|
||||
using namespace voidlibc::format;
|
||||
|
||||
WriteResult write_empty(const std::filesystem::path& out_path) {
|
||||
std::ofstream out(out_path, std::ios::binary | std::ios::trunc);
|
||||
if (!out) {
|
||||
return {false, "could not open output: " + out_path.string()};
|
||||
}
|
||||
|
||||
FileHeader hdr{};
|
||||
hdr.magic = kMagic;
|
||||
hdr.version_major = kVersionMajor;
|
||||
hdr.version_minor = kVersionMinor;
|
||||
hdr.flags = static_cast<std::uint32_t>(ContainerFlags::None);
|
||||
hdr.arch = TargetArch::X86_64;
|
||||
hdr.reserved = 0;
|
||||
hdr.section_count = 0;
|
||||
|
||||
// Everything after the header is empty; point offsets at the end of
|
||||
// the header so a reader walking pointers lands on valid, zero-size
|
||||
// regions instead of stale zeros.
|
||||
const std::uint64_t tail = sizeof(FileHeader);
|
||||
hdr.section_dir_off = tail;
|
||||
hdr.symtab_off = tail;
|
||||
hdr.symtab_size = 0;
|
||||
hdr.imports_off = tail;
|
||||
hdr.imports_size = 0;
|
||||
hdr.exports_off = tail;
|
||||
hdr.exports_size = 0;
|
||||
hdr.file_size = tail;
|
||||
|
||||
out.write(reinterpret_cast<const char*>(&hdr), sizeof(hdr));
|
||||
if (!out) {
|
||||
return {false, "write failed"};
|
||||
}
|
||||
return {true, {}};
|
||||
}
|
||||
|
||||
} // namespace voidlibc::voidlink
|
||||
Reference in new issue
Block a user