[lld-link] implement -lto-obj-path
Summary: This adds the -lto-obj-path option to lld-link. This can be used to specify a path at which to write a native object file for the full LTO part when using LTO unit splitting. Reviewers: ruiu, tejohnson, pcc, rnk Reviewed By: ruiu, rnk Subscribers: mehdi_amini, steven_wu, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65964 llvm-svn: 369559
This commit is contained in:
		
							parent
							
								
									969b3e6a8f
								
							
						
					
					
						commit
						5375b94e36
					
				| 
						 | 
					@ -190,6 +190,9 @@ struct Configuration {
 | 
				
			||||||
  // Used for /thinlto-object-suffix-replace:
 | 
					  // Used for /thinlto-object-suffix-replace:
 | 
				
			||||||
  std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
 | 
					  std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Used for /lto-obj-path:
 | 
				
			||||||
 | 
					  llvm::StringRef ltoObjPath;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  uint64_t align = 4096;
 | 
					  uint64_t align = 4096;
 | 
				
			||||||
  uint64_t imageBase = -1;
 | 
					  uint64_t imageBase = -1;
 | 
				
			||||||
  uint64_t fileAlign = 512;
 | 
					  uint64_t fileAlign = 512;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1475,6 +1475,7 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
 | 
				
			||||||
      getOldNewOptions(args, OPT_thinlto_prefix_replace);
 | 
					      getOldNewOptions(args, OPT_thinlto_prefix_replace);
 | 
				
			||||||
  config->thinLTOObjectSuffixReplace =
 | 
					  config->thinLTOObjectSuffixReplace =
 | 
				
			||||||
      getOldNewOptions(args, OPT_thinlto_object_suffix_replace);
 | 
					      getOldNewOptions(args, OPT_thinlto_object_suffix_replace);
 | 
				
			||||||
 | 
					  config->ltoObjPath = args.getLastArgValue(OPT_lto_obj_path);
 | 
				
			||||||
  // Handle miscellaneous boolean flags.
 | 
					  // Handle miscellaneous boolean flags.
 | 
				
			||||||
  config->allowBind = args.hasFlag(OPT_allowbind, OPT_allowbind_no, true);
 | 
					  config->allowBind = args.hasFlag(OPT_allowbind, OPT_allowbind_no, true);
 | 
				
			||||||
  config->allowIsolation =
 | 
					  config->allowIsolation =
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -177,6 +177,8 @@ std::vector<StringRef> BitcodeCompiler::compile() {
 | 
				
			||||||
  // files. After that, we exit from linker and ThinLTO backend runs in a
 | 
					  // files. After that, we exit from linker and ThinLTO backend runs in a
 | 
				
			||||||
  // distributed environment.
 | 
					  // distributed environment.
 | 
				
			||||||
  if (config->thinLTOIndexOnly) {
 | 
					  if (config->thinLTOIndexOnly) {
 | 
				
			||||||
 | 
					    if (!config->ltoObjPath.empty())
 | 
				
			||||||
 | 
					      saveBuffer(buf[0], config->ltoObjPath);
 | 
				
			||||||
    if (indexFile)
 | 
					    if (indexFile)
 | 
				
			||||||
      indexFile->close();
 | 
					      indexFile->close();
 | 
				
			||||||
    return {};
 | 
					    return {};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -191,6 +191,9 @@ def thinlto_object_suffix_replace : P<
 | 
				
			||||||
def thinlto_prefix_replace: P<
 | 
					def thinlto_prefix_replace: P<
 | 
				
			||||||
    "thinlto-prefix-replace",
 | 
					    "thinlto-prefix-replace",
 | 
				
			||||||
    "'old;new' replace old prefix with new prefix in ThinLTO outputs">;
 | 
					    "'old;new' replace old prefix with new prefix in ThinLTO outputs">;
 | 
				
			||||||
 | 
					def lto_obj_path : P<
 | 
				
			||||||
 | 
					    "lto-obj-path",
 | 
				
			||||||
 | 
					    "output native object for merged LTO unit to this path">;
 | 
				
			||||||
def dash_dash_version : Flag<["--"], "version">,
 | 
					def dash_dash_version : Flag<["--"], "version">,
 | 
				
			||||||
  HelpText<"Print version information">;
 | 
					  HelpText<"Print version information">;
 | 
				
			||||||
defm threads: B<"threads",
 | 
					defm threads: B<"threads",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,25 @@
 | 
				
			||||||
 | 
					; REQUIRES: x86
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Test to ensure that thinlto-index-only with lto-obj-path creates
 | 
				
			||||||
 | 
					; the native object file.
 | 
				
			||||||
 | 
					; RUN: opt -module-summary %s -o %t1.obj
 | 
				
			||||||
 | 
					; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.obj
 | 
				
			||||||
 | 
					; RUN: rm -f %t4.obj
 | 
				
			||||||
 | 
					; RUN: lld-link -thinlto-index-only -lto-obj-path:%t4.obj -out:t3.exe \
 | 
				
			||||||
 | 
					; RUN:     -entry:main %t1.obj %t2.obj
 | 
				
			||||||
 | 
					; RUN: llvm-readobj -h %t4.obj | FileCheck %s
 | 
				
			||||||
 | 
					; RUN: llvm-nm %t4.obj 2>&1 | FileCheck %s -check-prefix=SYMBOLS
 | 
				
			||||||
 | 
					; RUN: llvm-nm %t4.obj 2>&1 | count 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; CHECK: Format: COFF-x86-64
 | 
				
			||||||
 | 
					; SYMBOLS: @feat.00
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
 | 
				
			||||||
 | 
					target triple = "x86_64-pc-windows-msvc19.0.24215"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					declare void @g(...)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define void @main() {
 | 
				
			||||||
 | 
					  call void (...) @g()
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue