[PATCH] D79050: [lld-macho][reland] Add basic symbol table output
Jez Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 28 16:13:16 PDT 2020
int3 created this revision.
int3 added reviewers: alexshap, christylee, smeenai, ruiu, MaskRay, pcc, Ktwu.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
int3 updated this revision to Diff 260789.
int3 added a comment.
int3 edited the summary of this revision.
int3 added a child revision: D79051: [lld-macho][reland] Add support for emitting dylibs with a single symbol.
add a comment
This diff implements basic support for writing a symbol table.
Attributes are loosely supported for extern symbols and not at all for
other types.
Initial version by Kellie Medlin <kelliem at fb.com>
Original diff got reverted due to UBSAN erroring over unaligned writes.
That has been fixed in the current diff with the following changes:
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -133,6 +133,9 @@ SymtabSection::SymtabSection(StringTableSection &stringTableSection)
: stringTableSection(stringTableSection) {
segname = segment_names::linkEdit;
name = section_names::symbolTable;
+ // TODO: When we introduce the SyntheticSections superclass, we should make
+ // all synthetic sections aligned to WordSize by default.
+ align = WordSize;
}
size_t SymtabSection::getSize() const {
diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -371,6 +371,7 @@ void Writer::assignAddresses(OutputSegment *seg) {
ArrayRef<InputSection *> sections = p.second;
for (InputSection *isec : sections) {
addr = alignTo(addr, isec->align);
+ // We must align the file offsets too to avoid misaligned writes of
+ // structs.
+ fileOff = alignTo(fileOff, isec->align);
isec->addr = addr;
addr += isec->getSize();
fileOff += isec->getFileSize();
@@ -396,6 +397,7 @@ void Writer::writeSections() {
uint64_t fileOff = seg->fileOff;
for (auto § : seg->getSections()) {
for (InputSection *isec : sect.second) {
+ fileOff = alignTo(fileOff, isec->align);
isec->writeTo(buf + fileOff);
fileOff += isec->getFileSize();
}
I don't think it's easy to write a test for alignment (that doesn't
involve brittly hard-coding file offsets), so there isn't one... but
UBSAN builds pass now.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D79050
Files:
lld/MachO/SyntheticSections.cpp
lld/MachO/SyntheticSections.h
lld/MachO/Writer.cpp
lld/test/MachO/symtab.s
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79050.260789.patch
Type: text/x-patch
Size: 9243 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200428/fd1400ff/attachment.bin>
More information about the llvm-commits
mailing list