diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -196,6 +196,7 @@ bool warnMissingEntry; bool warnSymbolOrdering; bool writeAddends; + bool mmapOutputFile; bool zCombreloc; bool zCopyreloc; bool zExecstack; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -947,6 +947,8 @@ args.hasFlag(OPT_warn_ifunc_textrel, OPT_no_warn_ifunc_textrel, false); config->warnSymbolOrdering = args.hasFlag(OPT_warn_symbol_ordering, OPT_no_warn_symbol_ordering, true); + config->mmapOutputFile = + args.hasFlag(OPT_mmap_output_file, OPT_no_mmap_output_file, true); config->zCombreloc = getZFlag(args, "combreloc", "nocombreloc", true); config->zCopyreloc = getZFlag(args, "copyreloc", "nocopyreloc", true); config->zExecstack = getZFlag(args, "execstack", "noexecstack", false); diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td --- a/lld/ELF/Options.td +++ b/lld/ELF/Options.td @@ -406,6 +406,10 @@ "Warn about problems with the symbol ordering file (default)", "Do not warn about problems with the symbol ordering file">; +defm mmap_output_file: B<"mmap-output-file", + "Map the output file for writing (default)", + "Do not map the output file for writing">; + def warn_unresolved_symbols: F<"warn-unresolved-symbols">, HelpText<"Report unresolved symbols as warnings">; @@ -566,7 +570,6 @@ def: F<"no-copy-dt-needed-entries">; def: F<"no-ctors-in-init-array">; def: F<"no-keep-memory">; -def: F<"no-mmap-output-file">; def: F<"no-pipeline-knowledge">; def: F<"no-warn-mismatch">; def: Flag<["-"], "p">; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -2594,6 +2594,8 @@ unsigned flags = 0; if (!config->relocatable) flags = FileOutputBuffer::F_executable; + if (!config->mmapOutputFile) + flags |= FileOutputBuffer::F_in_memory; Expected> bufferOrErr = FileOutputBuffer::create(config->outputFile, fileSize, flags); diff --git a/lld/test/ELF/mmap-output-file.s b/lld/test/ELF/mmap-output-file.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/mmap-output-file.s @@ -0,0 +1,14 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -mmap-output-file -o %t1 +# RUN: llvm-objdump -d %t1 | FileCheck %s + +# CHECK: nop + +# RUN: ld.lld %t.o -no-mmap-output-file -o %t2 +# RUN: diff %t1 %t2 + +.globl _start +_start: + nop diff --git a/lld/test/ELF/silent-ignore.test b/lld/test/ELF/silent-ignore.test --- a/lld/test/ELF/silent-ignore.test +++ b/lld/test/ELF/silent-ignore.test @@ -6,7 +6,6 @@ RUN: -no-copy-dt-needed-entries \ RUN: -no-ctors-in-init-array \ RUN: -no-keep-memory \ -RUN: -no-mmap-output-file \ RUN: -no-pipeline-knowledge \ RUN: -no-warn-mismatch \ RUN: -p \