[lld] [LLD][COFF] Add support for custom DOS stub (PR #122561)

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 14 04:00:41 PST 2025


================
@@ -246,6 +246,21 @@ void LinkerDriver::parseAligncomm(StringRef s) {
       std::max(ctx.config.alignComm[std::string(name)], 1 << v);
 }
 
+void LinkerDriver::parseStub(StringRef path) {
+  std::unique_ptr<MemoryBuffer> stub =
+      CHECK(MemoryBuffer::getFile(path), "could not open " + path);
+  size_t bufferSize = stub->getBufferSize();
+  const char *bufferStart = stub->getBufferStart();
+  // MS link.exe compatibility:
+  // 1. stub must be greater or equal than 64 bytes
+  // 2. stub must be 8-byte aligned
----------------
zmodem wrote:

I don't feel too strongly about it, but unless there's a technical reason to reject such stubs, I think we should accept also non-8-byte-aligned programs and add any padding ourselves.

https://learn.microsoft.com/en-us/cpp/build/reference/stub-ms-dos-stub-file-name?view=msvc-170 says "any valid MS-DOS application [.exe file] can be a stub program", for example.

https://github.com/llvm/llvm-project/pull/122561


More information about the llvm-commits mailing list