[lld] [LLD][COFF] Add support for custom section layout (PR #152779)
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 29 01:21:03 PDT 2025
================
@@ -214,6 +214,46 @@ void LinkerDriver::parseSection(StringRef s) {
ctx.config.section[name] = parseSectionAttributes(ctx, attrs);
}
+// Parses /sectionlayout:@ option argument.
+void LinkerDriver::parseSectionLayout(StringRef path) {
+ if (path.starts_with("@"))
+ path = path.substr(1);
+ std::unique_ptr<MemoryBuffer> layoutFile =
+ CHECK(MemoryBuffer::getFile(path), "could not open " + path);
+ StringRef content = layoutFile->getBuffer();
+ int index = 0;
+
+ while (!content.empty()) {
+ size_t pos = content.find_first_of("\r\n");
+ StringRef line;
+
+ if (pos == StringRef::npos) {
+ line = content;
+ content = StringRef();
+ } else {
+ line = content.substr(0, pos);
+ content = content.substr(pos);
+ while (!content.empty() && (content[0] == '\r' || content[0] == '\n'))
+ content = content.substr(1);
+ }
+
+ line = line.trim();
+ if (line.empty())
+ continue;
+
+ StringRef sectionName = line.split(' ').first;
----------------
mstorsjo wrote:
So this ignores anything after a space on each line? On a quick glance through the tests, I don't see any of the tests exercising that aspect.
https://github.com/llvm/llvm-project/pull/152779
More information about the llvm-commits
mailing list