Index: lld/trunk/COFF/Driver.cpp =================================================================== --- lld/trunk/COFF/Driver.cpp +++ lld/trunk/COFF/Driver.cpp @@ -307,6 +307,18 @@ return DebugTypes; } +static std::string getMapFile(const opt::InputArgList &Args) { + auto *Arg = Args.getLastArg(OPT_lldmap, OPT_lldmap_file); + if (!Arg) + return ""; + if (Arg->getOption().getID() == OPT_lldmap_file) + return Arg->getValue(); + + assert(Arg->getOption().getID() == OPT_lldmap); + StringRef OutFile = Config->OutputFile; + return (OutFile.substr(0, OutFile.rfind('.')) + ".map").str(); +} + void LinkerDriver::link(ArrayRef ArgsArr) { // If the first command line argument is "/lib", link.exe acts like lib.exe. // We call our own implementation of lib.exe that understands bitcode files. @@ -763,13 +775,15 @@ // Create a symbol map file containing symbol VAs and their names // to help debugging. - if (auto *Arg = Args.getLastArg(OPT_lldmap)) { + std::string MapFile = getMapFile(Args); + if (!MapFile.empty()) { std::error_code EC; - raw_fd_ostream Out(Arg->getValue(), EC, OpenFlags::F_Text); + raw_fd_ostream Out(MapFile, EC, OpenFlags::F_Text); if (EC) - fatal(EC, "could not create the symbol map"); + fatal(EC, "could not create the symbol map " + MapFile); Symtab.printMap(Out); } + // Call exit to avoid calling destructors. exit(0); } Index: lld/trunk/COFF/Options.td =================================================================== --- lld/trunk/COFF/Options.td +++ lld/trunk/COFF/Options.td @@ -95,7 +95,8 @@ // Flags for debugging def dumppdb : Joined<["/", "-"], "dumppdb">; -def lldmap : Joined<["/", "-"], "lldmap:">; +def lldmap : F<"lldmap">; +def lldmap_file : Joined<["/", "-"], "lldmap:">; //============================================================================== // The flags below do nothing. They are defined only for link.exe compatibility. Index: lld/trunk/test/COFF/lldmap.test =================================================================== --- lld/trunk/test/COFF/lldmap.test +++ lld/trunk/test/COFF/lldmap.test @@ -1,6 +1,8 @@ # RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj -# RUN: lld-link /out:%t.exe /entry:main /lldmap:%t.map %t.obj -# RUN: FileCheck %s < %t.map +# RUN: lld-link /out:%t.exe /entry:main /lldmap:%T/foo.map %t.obj +# RUN: FileCheck %s < %T/foo.map +# RUN: lld-link /out:%T/bar.exe /entry:main /lldmap %t.obj +# RUN: FileCheck %s < %T/bar.map # CHECK: .obj: # CHECK-NEXT: 140001000 .text$mn