command_line_overflow_fix cleaned

This commit is contained in:
Paul Naert 2018-05-10 14:35:24 -07:00
parent 32cb46a01d
commit 3c8bf6aa47

View File

@ -43,7 +43,6 @@ import (
"os/exec" "os/exec"
"path" "path"
"path/filepath" "path/filepath"
"reflect"
"runtime" "runtime"
"sort" "sort"
"strconv" "strconv"
@ -463,7 +462,7 @@ func formatStdOut(stdout bytes.Buffer, usefulIndex int) string {
func extractTimeLinkFiles(ea extractionArgs, filesToLink []string) { func extractTimeLinkFiles(ea extractionArgs, filesToLink []string) {
var linkArgs []string var linkArgs []string
var tmpFileList []string var tmpFileList []string
// Extracting the command line max size from the environment
getArgMax := exec.Command("getconf", "ARG_MAX") getArgMax := exec.Command("getconf", "ARG_MAX")
var argMaxStr bytes.Buffer var argMaxStr bytes.Buffer
getArgMax.Stdout = &argMaxStr getArgMax.Stdout = &argMaxStr
@ -479,7 +478,7 @@ func extractTimeLinkFiles(ea extractionArgs, filesToLink []string) {
linkArgs = append(linkArgs, "-v") linkArgs = append(linkArgs, "-v")
} }
if getsize(filesToLink) > argMax { if getsize(filesToLink) > argMax { //command line size too large for the OS
// Create tmp dir // Create tmp dir
tmpDirName, err := ioutil.TempDir("", "glinking") tmpDirName, err := ioutil.TempDir("", "glinking")
@ -494,7 +493,7 @@ func extractTimeLinkFiles(ea extractionArgs, filesToLink []string) {
tmpFileList = append(tmpFileList, tmpFile.Name()) tmpFileList = append(tmpFileList, tmpFile.Name())
linkArgs = append(linkArgs, "-o", tmpFile.Name()) linkArgs = append(linkArgs, "-o", tmpFile.Name())
LogInfo("llvm-link argument size : %d, or %d", uintptr(len(filesToLink))*reflect.TypeOf(linkArgs).Elem().Size(), getsize(filesToLink)) LogInfo("llvm-link argument size : %d", getsize(filesToLink))
for _, file := range filesToLink { for _, file := range filesToLink {
linkArgs = append(linkArgs, file) linkArgs = append(linkArgs, file)
if getsize(linkArgs) > (argMax - 10000) { //keeping a small margin if getsize(linkArgs) > (argMax - 10000) { //keeping a small margin
@ -530,7 +529,7 @@ func extractTimeLinkFiles(ea extractionArgs, filesToLink []string) {
if !success { if !success {
LogFatal("There was an error linking input files into %s because %v.\n", ea.OutputFile, err) LogFatal("There was an error linking input files into %s because %v.\n", ea.OutputFile, err)
} }
LogWarning("Bitcode file extracted to: %s, from files %v \n", ea.OutputFile, tmpFileList)
} else { } else {
linkArgs = append(linkArgs, "-o", ea.OutputFile) linkArgs = append(linkArgs, "-o", ea.OutputFile)
linkArgs = append(linkArgs, filesToLink...) linkArgs = append(linkArgs, filesToLink...)
@ -538,8 +537,9 @@ func extractTimeLinkFiles(ea extractionArgs, filesToLink []string) {
if !success { if !success {
LogFatal("There was an error linking input files into %s because %v.\n", ea.OutputFile, err) LogFatal("There was an error linking input files into %s because %v.\n", ea.OutputFile, err)
} }
LogWarning("Bitcode file extracted to: %s \n", ea.OutputFile)
} }
LogWarning("Bitcode file extracted to: %s, from files %v \n", ea.OutputFile, tmpFileList)
} }
func extractSectionDarwin(inputFile string) (contents []string) { func extractSectionDarwin(inputFile string) (contents []string) {