Skip to content

Commit 05cd088

Browse files
committed
slightly more documented LD
1 parent 9f9bbbe commit 05cd088

File tree

1 file changed

+14
-7
lines changed
  • graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell

1 file changed

+14
-7
lines changed

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonLD.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
import jline.internal.InputStreamReader;
5858

5959
public class GraalPythonLD extends GraalPythonCompiler {
60+
private static final String LLVM_IR_BITCODE = "llvm-ir-bitcode";
61+
private static final String LLVM_NM = "llvm-nm";
6062
private static List<String> linkPrefix = Arrays.asList(new String[]{
6163
"llvm-link",
6264
"-o",
@@ -106,7 +108,7 @@ private void parseOptions(String[] args) {
106108
List<String> bcFiles = searchLib(libraryDirs, arg.substring(2));
107109
for (String bcFile : bcFiles) {
108110
try {
109-
if (Files.probeContentType(Paths.get(bcFile)).contains("llvm-ir-bitcode")) {
111+
if (Files.probeContentType(Paths.get(bcFile)).contains(LLVM_IR_BITCODE)) {
110112
logV("library input:", bcFile);
111113
addFile(bcFile);
112114
} else {
@@ -133,7 +135,7 @@ void addFile(String f) {
133135
try {
134136
// symbols defined up to here
135137
ProcessBuilder nm = new ProcessBuilder();
136-
nm.command("llvm-nm", "-g", "--defined-only", f);
138+
nm.command(LLVM_NM, "-g", "--defined-only", f);
137139
nm.redirectInput(Redirect.INHERIT);
138140
nm.redirectError(Redirect.INHERIT);
139141
nm.redirectOutput(Redirect.PIPE);
@@ -153,7 +155,7 @@ void addFile(String f) {
153155
undefinedSymbols.removeAll(definedSymbols);
154156

155157
// add symbols undefined now
156-
nm.command("llvm-nm", "-u", f);
158+
nm.command(LLVM_NM, "-u", f);
157159
nm.redirectInput(Redirect.INHERIT);
158160
nm.redirectError(Redirect.INHERIT);
159161
nm.redirectOutput(Redirect.PIPE);
@@ -235,13 +237,18 @@ private Collection<? extends String> arMembers(String path) throws IOException,
235237
extractAr.start().waitFor();
236238

237239
// ar has special semantics w.r.t ordering of included symbols. we try to emulate the smarts
238-
// of GNU ld by listing all undefined symbols until here, extracting only those, and adding
239-
// only these
240+
// of GNU ld by listing all undefined symbols until here, extracting only those that we are
241+
// still missing, and adding them to a bitcode file that will only add these to the linked
242+
// product.
243+
// According to some emscripten documentation and ML discussions, this is actually an error
244+
// in the build process, because such a smart linker should not be assumed for POSIX, but it
245+
// seems ok to emulate this at least for the very common case of ar archives with symbol
246+
// definitions that overlap what's defined in explicitly include .o files
240247
for (String f : members) {
241-
if (Files.probeContentType(Paths.get(f)).contains("llvm-ir-bitcode")) {
248+
if (Files.probeContentType(Paths.get(f)).contains(LLVM_IR_BITCODE)) {
242249
HashSet<String> definedHere = new HashSet<>();
243250
ProcessBuilder nm = new ProcessBuilder();
244-
nm.command("llvm-nm", "-g", "--defined-only", f);
251+
nm.command(LLVM_NM, "-g", "--defined-only", f);
245252
nm.redirectInput(Redirect.INHERIT);
246253
nm.redirectError(Redirect.INHERIT);
247254
nm.redirectOutput(Redirect.PIPE);

0 commit comments

Comments
 (0)