Bläddra i källkod

Add support for LLVM nm. (#545)

Garrett Wang 4 år sedan
förälder
incheckning
d500996d7c
No account linked to committer's email address
1 ändrade filer med 27 tillägg och 9 borttagningar
  1. 27
    9
      internal/binutils/binutils.go

+ 27
- 9
internal/binutils/binutils.go Visa fil

137
 	}
137
 	}
138
 
138
 
139
 	defaultPath := paths[""]
139
 	defaultPath := paths[""]
140
-	b.llvmSymbolizer, b.llvmSymbolizerFound = findExe("llvm-symbolizer", append(paths["llvm-symbolizer"], defaultPath...))
141
-	b.addr2line, b.addr2lineFound = findExe("addr2line", append(paths["addr2line"], defaultPath...))
142
-	if !b.addr2lineFound {
143
-		// On MacOS, brew installs addr2line under gaddr2line name, so search for
144
-		// that if the tool is not found by its default name.
145
-		b.addr2line, b.addr2lineFound = findExe("gaddr2line", append(paths["addr2line"], defaultPath...))
146
-	}
147
-	b.nm, b.nmFound = findExe("nm", append(paths["nm"], defaultPath...))
140
+	b.llvmSymbolizer, b.llvmSymbolizerFound = chooseExe([]string{"llvm-symbolizer"}, []string{}, append(paths["llvm-symbolizer"], defaultPath...))
141
+	b.addr2line, b.addr2lineFound = chooseExe([]string{"addr2line"}, []string{"gaddr2line"}, append(paths["addr2line"], defaultPath...))
142
+	// The "-n" option is supported by LLVM since 2011. The output of llvm-nm
143
+	// and GNU nm with "-n" option is interchangeable for our purposes, so we do
144
+	// not need to differrentiate them.
145
+	b.nm, b.nmFound = chooseExe([]string{"llvm-nm", "nm"}, []string{"gnm"}, append(paths["nm"], defaultPath...))
148
 	b.objdump, b.objdumpFound, b.isLLVMObjdump = findObjdump(append(paths["objdump"], defaultPath...))
146
 	b.objdump, b.objdumpFound, b.isLLVMObjdump = findObjdump(append(paths["objdump"], defaultPath...))
149
 }
147
 }
150
 
148
 
155
 // a string with path to the preferred objdump binary if found,
153
 // a string with path to the preferred objdump binary if found,
156
 // or an empty string if not found;
154
 // or an empty string if not found;
157
 // a boolean if any acceptable objdump was found;
155
 // a boolean if any acceptable objdump was found;
158
-// a boolen indicating if it is an LLVM objdump.
156
+// a boolean indicating if it is an LLVM objdump.
159
 func findObjdump(paths []string) (string, bool, bool) {
157
 func findObjdump(paths []string) (string, bool, bool) {
160
 	objdumpNames := []string{"llvm-objdump", "objdump"}
158
 	objdumpNames := []string{"llvm-objdump", "objdump"}
161
 	if runtime.GOOS == "darwin" {
159
 	if runtime.GOOS == "darwin" {
179
 	return "", false, false
177
 	return "", false, false
180
 }
178
 }
181
 
179
 
180
+// chooseExe finds and returns path to preferred binary. names is a list of
181
+// names to search on both Linux and OSX. osxNames is a list of names specific
182
+// to OSX. names always has a higher priority than osxNames. The order of
183
+// the name within each list decides its priority (e.g. the first name has a
184
+// higher priority than the second name in the list).
185
+//
186
+// It returns a string with path to the binary and a boolean indicating if any
187
+// acceptable binary was found.
188
+func chooseExe(names, osxNames []string, paths []string) (string, bool) {
189
+	if runtime.GOOS == "darwin" {
190
+		names = append(names, osxNames...)
191
+	}
192
+	for _, name := range names {
193
+		if binary, found := findExe(name, paths); found {
194
+			return binary, true
195
+		}
196
+	}
197
+	return "", false
198
+}
199
+
182
 // isLLVMObjdump accepts a string with path to an objdump binary,
200
 // isLLVMObjdump accepts a string with path to an objdump binary,
183
 // and returns a boolean indicating if the given binary is an LLVM
201
 // and returns a boolean indicating if the given binary is an LLVM
184
 // objdump binary of an acceptable version.
202
 // objdump binary of an acceptable version.