[all-commits] [llvm/llvm-project] 4f0ccc: [lld-macho][reland] Add basic symbol table output
Jez Ng via All-commits
all-commits at lists.llvm.org
Tue Apr 28 17:09:11 PDT 2020
Branch: refs/heads/master
Home: https://github.com/llvm/llvm-project
Commit: 4f0cccdd7a06ff60d3271638f47082b65f3793f1
https://github.com/llvm/llvm-project/commit/4f0cccdd7a06ff60d3271638f47082b65f3793f1
Author: Jez Ng <jezng at fb.com>
Date: 2020-04-28 (Tue, 28 Apr 2020)
Changed paths:
M lld/MachO/SyntheticSections.cpp
M lld/MachO/SyntheticSections.h
M lld/MachO/Writer.cpp
A lld/test/MachO/symtab.s
Log Message:
-----------
[lld-macho][reland] Add basic symbol table output
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>
Originally committed in a3d95a50ee33 and reverted in fbae153ca583 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.
Differential Revision: https://reviews.llvm.org/D79050
Commit: 62b8f32f7699807ec61c81e2ffceae584a7e6219
https://github.com/llvm/llvm-project/commit/62b8f32f7699807ec61c81e2ffceae584a7e6219
Author: Jez Ng <jezng at fb.com>
Date: 2020-04-28 (Tue, 28 Apr 2020)
Changed paths:
M lld/MachO/Config.h
M lld/MachO/Driver.cpp
M lld/MachO/Options.td
M lld/MachO/SyntheticSections.cpp
M lld/MachO/SyntheticSections.h
M lld/MachO/Writer.cpp
R lld/test/MachO/Inputs/goodbye-dylib.yaml
R lld/test/MachO/Inputs/hello-dylib.yaml
A lld/test/MachO/Inputs/libgoodbye.s
A lld/test/MachO/Inputs/libhello.s
A lld/test/MachO/dylib.s
M lld/test/MachO/dylink.s
M lld/test/MachO/load-commands.s
M lld/test/MachO/symtab.s
Log Message:
-----------
[lld-macho][reland] Add support for emitting dylibs with a single symbol
This got reverted due to UBSAN errors in a diff lower in the stack,
which is being fixed in https://reviews.llvm.org/D79050. This diff is
otherwise identical to the original https://reviews.llvm.org/D76908
(which was committed in 9598778bd191 and reverted in b52bc2653bbc).
Differential Revision: https://reviews.llvm.org/D79051
Compare: https://github.com/llvm/llvm-project/compare/3421d1ede4c1...62b8f32f7699
More information about the All-commits
mailing list