2018-12-19 15:24:38 +08:00
|
|
|
//===- Writer.h -------------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2018-12-19 15:24:38 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TOOLS_OBJCOPY_COFF_WRITER_H
|
|
|
|
#define LLVM_TOOLS_OBJCOPY_COFF_WRITER_H
|
|
|
|
|
|
|
|
#include "Buffer.h"
|
|
|
|
#include "llvm/MC/StringTableBuilder.h"
|
2018-12-31 04:35:43 +08:00
|
|
|
#include "llvm/Support/Error.h"
|
2018-12-19 15:24:38 +08:00
|
|
|
#include <cstddef>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace objcopy {
|
|
|
|
namespace coff {
|
|
|
|
|
2018-12-19 15:45:06 +08:00
|
|
|
struct Object;
|
2018-12-19 15:24:38 +08:00
|
|
|
|
2019-01-12 16:30:09 +08:00
|
|
|
class COFFWriter {
|
2018-12-19 15:24:38 +08:00
|
|
|
Object &Obj;
|
|
|
|
Buffer &Buf;
|
|
|
|
|
|
|
|
size_t FileSize;
|
|
|
|
size_t FileAlignment;
|
|
|
|
size_t SizeOfInitializedData;
|
|
|
|
StringTableBuilder StrTabBuilder;
|
|
|
|
|
[llvm-objcopy] [COFF] Fix handling of aux symbols for big objects
The aux symbols were stored in an opaque std::vector<uint8_t>,
with contents interpreted according to the rest of the symbol.
All aux symbol types but one fit in 18 bytes (sizeof(coff_symbol16)),
and if written to a bigobj, two extra padding bytes are written (as
sizeof(coff_symbol32) is 20). In the storage agnostic intermediate
representation, store the aux symbols as a series of coff_symbol16
sized opaque blobs. (In practice, all such aux symbols only consist
of one aux symbol, so this is more flexible than what reality needs.)
The special case is the file aux symbols, which are written in
potentially more than one aux symbol slot, without any padding,
as one single long string. This can't be stored in the same opaque
vector of fixed sized aux symbol entries. The file aux symbols will
occupy a different number of aux symbol slots depending on the type
of output object file. As nothing in the intermediate process needs
to have accurate raw symbol indices, updating that is moved into the
writer class.
Differential Revision: https://reviews.llvm.org/D57009
llvm-svn: 351947
2019-01-23 19:54:51 +08:00
|
|
|
template <class SymbolTy> std::pair<size_t, size_t> finalizeSymbolTable();
|
2019-01-11 05:28:24 +08:00
|
|
|
Error finalizeRelocTargets();
|
2019-01-22 18:58:09 +08:00
|
|
|
Error finalizeSymbolContents();
|
2018-12-19 15:24:38 +08:00
|
|
|
void layoutSections();
|
|
|
|
size_t finalizeStringTable();
|
|
|
|
|
2019-01-11 05:28:24 +08:00
|
|
|
Error finalize(bool IsBigObj);
|
2018-12-19 15:24:38 +08:00
|
|
|
|
|
|
|
void writeHeaders(bool IsBigObj);
|
|
|
|
void writeSections();
|
|
|
|
template <class SymbolTy> void writeSymbolStringTables();
|
|
|
|
|
2018-12-31 04:35:43 +08:00
|
|
|
Error write(bool IsBigObj);
|
2018-12-19 15:24:38 +08:00
|
|
|
|
2018-12-31 04:35:43 +08:00
|
|
|
Error patchDebugDirectory();
|
2018-12-19 15:24:38 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~COFFWriter() {}
|
2019-01-12 16:30:09 +08:00
|
|
|
Error write();
|
2018-12-19 15:24:38 +08:00
|
|
|
|
|
|
|
COFFWriter(Object &Obj, Buffer &Buf)
|
2019-01-12 16:30:09 +08:00
|
|
|
: Obj(Obj), Buf(Buf), StrTabBuilder(StringTableBuilder::WinCOFF) {}
|
2018-12-19 15:24:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace coff
|
|
|
|
} // end namespace objcopy
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif // LLVM_TOOLS_OBJCOPY_COFF_WRITER_H
|