// unfinalized inputs[finalIdx].
fatal(Twine(__FUNCTION__) + ": FIXME: thunk range overrun");
}
- thunkInfo.isec = make<ConcatInputSection>();
- thunkInfo.isec->name = isec->name;
- thunkInfo.isec->segname = isec->segname;
+ thunkInfo.isec = make<ConcatInputSection>(isec->segname, isec->name);
thunkInfo.isec->parent = this;
StringRef thunkName = saver.save(funcSym->getName() + ".thunk." +
std::to_string(thunkInfo.sequence++));
if (common == nullptr)
continue;
- auto *isec = make<ConcatInputSection>();
+ auto *isec =
+ make<ConcatInputSection>(segment_names::data, section_names::common);
isec->file = common->getFile();
- isec->name = section_names::common;
- isec->segname = segment_names::data;
isec->align = common->align;
// Casting to size_t will truncate large values on 32-bit architectures,
// but it's not really worth supporting the linking of 64-bit programs on
: id(idCount++), fileKind(kind), name(saver.save(interface.getPath())) {}
template <class Section>
-static void parseSection(ObjFile *file, const uint8_t *buf, const Section &sec,
- InputSection *isec) {
- isec->file = file;
- isec->name =
- StringRef(sec.sectname, strnlen(sec.sectname, sizeof(sec.sectname)));
- isec->segname =
- StringRef(sec.segname, strnlen(sec.segname, sizeof(sec.segname)));
- isec->data = {isZeroFill(sec.flags) ? nullptr : buf + sec.offset,
- static_cast<size_t>(sec.size)};
- if (sec.align >= 32)
- error("alignment " + std::to_string(sec.align) + " of section " +
- isec->name + " is too large");
- else
- isec->align = 1 << sec.align;
- isec->flags = sec.flags;
-}
-
-template <class Section>
void ObjFile::parseSections(ArrayRef<Section> sections) {
subsections.reserve(sections.size());
auto *buf = reinterpret_cast<const uint8_t *>(mb.getBufferStart());
for (const Section &sec : sections) {
+ StringRef name =
+ StringRef(sec.sectname, strnlen(sec.sectname, sizeof(sec.sectname)));
+ StringRef segname =
+ StringRef(sec.segname, strnlen(sec.segname, sizeof(sec.segname)));
+ ArrayRef<uint8_t> data = {isZeroFill(sec.flags) ? nullptr
+ : buf + sec.offset,
+ static_cast<size_t>(sec.size)};
+ if (sec.align >= 32)
+ error("alignment " + std::to_string(sec.align) + " of section " + name +
+ " is too large");
+ uint32_t align = 1 << sec.align;
+ uint32_t flags = sec.flags;
+
if (config->dedupLiterals &&
(sectionType(sec.flags) == S_CSTRING_LITERALS ||
isWordLiteralSection(sec.flags))) {
InputSection *isec;
if (sectionType(sec.flags) == S_CSTRING_LITERALS) {
- isec = make<CStringInputSection>();
- parseSection(this, buf, sec, isec);
+ isec =
+ make<CStringInputSection>(segname, name, this, data, align, flags);
// FIXME: parallelize this?
cast<CStringInputSection>(isec)->splitIntoPieces();
} else {
- isec = make<WordLiteralInputSection>();
- parseSection(this, buf, sec, isec);
+ isec = make<WordLiteralInputSection>(segname, name, this, data, align,
+ flags);
}
subsections.push_back({{0, isec}});
} else {
- auto *isec = make<ConcatInputSection>();
- parseSection(this, buf, sec, isec);
+ auto *isec =
+ make<ConcatInputSection>(segname, name, this, data, align, flags);
if (!(isDebugSection(isec->flags) &&
isec->segname == segment_names::dwarf)) {
subsections.push_back({{0, isec}});
OpaqueFile::OpaqueFile(MemoryBufferRef mb, StringRef segName,
StringRef sectName)
: InputFile(OpaqueKind, mb) {
- ConcatInputSection *isec = make<ConcatInputSection>();
+ ConcatInputSection *isec =
+ make<ConcatInputSection>(segName.take_front(16), sectName.take_front(16));
isec->file = this;
- isec->name = sectName.take_front(16);
- isec->segname = segName.take_front(16);
const auto *buf = reinterpret_cast<const uint8_t *>(mb.getBufferStart());
isec->data = {buf, mb.getBufferSize()};
isec->live = true;
return piece.outSecOff + addend;
}
+WordLiteralInputSection::WordLiteralInputSection(StringRef segname,
+ StringRef name,
+ InputFile *file,
+ ArrayRef<uint8_t> data,
+ uint32_t align, uint32_t flags)
+ : InputSection(WordLiteralKind, segname, name, file, data, align, flags) {}
+
uint64_t WordLiteralInputSection::getFileOffset(uint64_t off) const {
return parent->fileOff + getOffset(off);
}
std::vector<Reloc> relocs;
protected:
- explicit InputSection(Kind kind) : sectionKind(kind) {}
+ InputSection(Kind kind, StringRef segname, StringRef name)
+ : name(name), segname(segname), sectionKind(kind) {}
+
+ InputSection(Kind kind, StringRef segname, StringRef name, InputFile *file,
+ ArrayRef<uint8_t> data, uint32_t align, uint32_t flags)
+ : file(file), name(name), segname(segname), align(align), flags(flags),
+ data(data), sectionKind(kind) {}
private:
Kind sectionKind;
// contents merged before output.
class ConcatInputSection : public InputSection {
public:
- ConcatInputSection() : InputSection(ConcatKind) {}
+ ConcatInputSection(StringRef segname, StringRef name)
+ : InputSection(ConcatKind, segname, name) {}
+
+ ConcatInputSection(StringRef segname, StringRef name, InputFile *file,
+ ArrayRef<uint8_t> data, uint32_t align, uint32_t flags)
+ : InputSection(ConcatKind, segname, name, file, data, align, flags) {}
+
uint64_t getFileOffset(uint64_t off) const override;
uint64_t getOffset(uint64_t off) const override { return outSecOff + off; }
uint64_t getVA() const { return InputSection::getVA(0); }
// conservative behavior we can certainly implement that.
class CStringInputSection : public InputSection {
public:
- CStringInputSection() : InputSection(CStringLiteralKind) {}
+ CStringInputSection(StringRef segname, StringRef name, InputFile *file,
+ ArrayRef<uint8_t> data, uint32_t align, uint32_t flags)
+ : InputSection(CStringLiteralKind, segname, name, file, data, align,
+ flags) {}
uint64_t getFileOffset(uint64_t off) const override;
uint64_t getOffset(uint64_t off) const override;
// FIXME implement this
class WordLiteralInputSection : public InputSection {
public:
- WordLiteralInputSection() : InputSection(WordLiteralKind) {}
+ WordLiteralInputSection(StringRef segname, StringRef name, InputFile *file,
+ ArrayRef<uint8_t> data, uint32_t align,
+ uint32_t flags);
uint64_t getFileOffset(uint64_t off) const override;
uint64_t getOffset(uint64_t off) const override;
// FIXME implement this
SyntheticSection::SyntheticSection(const char *segname, const char *name)
: OutputSection(SyntheticKind, name), segname(segname) {
- isec = make<ConcatInputSection>();
- isec->segname = segname;
- isec->name = name;
+ isec = make<ConcatInputSection>(segname, name);
isec->parent = this;
syntheticSections.push_back(this);
}
/*noDeadStrip=*/false);
}
-ImageLoaderCacheSection::ImageLoaderCacheSection() {
- segname = segment_names::data;
- name = section_names::data;
+ImageLoaderCacheSection::ImageLoaderCacheSection()
+ : ConcatInputSection(segment_names::data, section_names::data) {
uint8_t *arr = bAlloc.Allocate<uint8_t>(target->wordSize);
memset(arr, 0, target->wordSize);
data = {arr, target->wordSize};