From c909e7786e36ddd450eaac2d3b5d062a70416638 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Tue, 29 Jun 2021 13:43:27 -0400 Subject: [PATCH 1/3] README: document LLVM_LINK_FLAGS --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 8c5ed8e..f48c956 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ bitcode in parallel, and is faster. A comparison between the two tools can be gl | LLVM_COMPILER | *not supported* (clang only)| | LLVM_GCC_PREFIX | *not supported* (clang only)| | LLVM_DRAGONEGG_PLUGIN | *not supported* (clang only)| +| LLVM_LINK_FLAGS | *not supported* | This project, `gllvm`, provides tools for building whole-program (or @@ -252,6 +253,11 @@ produces the bitcode. This can be fulfilled by setting the `LLVM_BITCODE_GENERATION_FLAGS` environment variable to the desired flags, for example `"-flto -fwhole-program-vtables"`. +In other situations it is desirable to pass certain flags to `llvm-link` in the step +that merges multiple individual bitcode files together (i.e., within `get-bc`). +This can be fulfilled by setting the `LLVM_LINK_FLAGS` environment variable to +the desired flags, for example `"-internalize -only-needed"`. + ## Beware of link time optimization. If the package you are building happens to take advantage of recent `clang` developments From b789b6b9cefc52ef2ccce9604714668121ff7463 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Tue, 29 Jun 2021 13:43:40 -0400 Subject: [PATCH 2/3] shared/environment: scaffolding for LLVM_LINK_FLAGS --- shared/environment.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shared/environment.go b/shared/environment.go index 19891c3..53969b9 100644 --- a/shared/environment.go +++ b/shared/environment.go @@ -68,6 +68,9 @@ var LLVMARName string //LLVMLINKName is the user configured name of the llvm-link. var LLVMLINKName string +//LLVMLINKFlags is the user configured list of flags to append to llvm-link. +var LLVMLINKFlags []string + //LLVMConfigureOnly is the user configured flag indicating a single pass mode is required. var LLVMConfigureOnly string @@ -99,6 +102,7 @@ const ( envf = "LLVM_F_NAME" envar = "LLVM_AR_NAME" envlnk = "LLVM_LINK_NAME" + envlnkflgs = "LLVM_LINK_FLAGS" envcfg = "WLLVM_CONFIGURE_ONLY" envbc = "WLLVM_BC_STORE" envlvl = "WLLVM_OUTPUT_LEVEL" @@ -142,6 +146,7 @@ func ResetEnvironment() { LLVMFName = "" LLVMARName = "" LLVMLINKName = "" + LLVMLINKFlags = []string{} LLVMConfigureOnly = "" LLVMBitcodeStorePath = "" LLVMLoggingLevel = "" @@ -160,6 +165,7 @@ func FetchEnvironment() { LLVMFName = os.Getenv(envf) LLVMARName = os.Getenv(envar) LLVMLINKName = os.Getenv(envlnk) + LLVMLINKFlags = strings.Fields(os.Getenv(envlnkflgs)) LLVMConfigureOnly = os.Getenv(envcfg) LLVMBitcodeStorePath = os.Getenv(envbc) From cd6d58d084a3789730ab2600faaafa8461807b2b Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Tue, 29 Jun 2021 14:04:57 -0400 Subject: [PATCH 3/3] extractor: inject LLVM_LINK_FLAGS --- shared/extractor.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/shared/extractor.go b/shared/extractor.go index 9228ba6..27ac672 100644 --- a/shared/extractor.go +++ b/shared/extractor.go @@ -661,6 +661,10 @@ func linkBitcodeFilesIncrementally(ea ExtractionArgs, filesToLink []string, argM if ea.Verbose { linkArgs = append(linkArgs, "-v") } + + // Append any custom llvm-link flags requested by the user. + // We only do this for the last llvm-link invocation. + linkArgs = append(linkArgs, LLVMLINKFlags...) linkArgs = append(linkArgs, tmpFileList...) linkArgs = append(linkArgs, "-o", ea.OutputFile) @@ -682,10 +686,15 @@ func linkBitcodeFiles(ea ExtractionArgs, filesToLink []string) (success bool) { if ea.Verbose { linkArgs = append(linkArgs, "-v") } + if getsize(filesToLink) > argMax { //command line size too large for the OS (necessitated by chromium) return linkBitcodeFilesIncrementally(ea, filesToLink, argMax, linkArgs) } var err error + + // Append any custom llvm-link flags requested by the user. + // N.B. that we do this specially for the incremental link case. + linkArgs = append(linkArgs, LLVMLINKFlags...) linkArgs = append(linkArgs, "-o", ea.OutputFile) linkArgs = append(linkArgs, filesToLink...) success, err = execCmd(ea.LlvmLinkerName, linkArgs, "")