57
57
import jline .internal .InputStreamReader ;
58
58
59
59
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" ;
60
62
private static List <String > linkPrefix = Arrays .asList (new String []{
61
63
"llvm-link" ,
62
64
"-o" ,
@@ -106,7 +108,7 @@ private void parseOptions(String[] args) {
106
108
List <String > bcFiles = searchLib (libraryDirs , arg .substring (2 ));
107
109
for (String bcFile : bcFiles ) {
108
110
try {
109
- if (Files .probeContentType (Paths .get (bcFile )).contains ("llvm-ir-bitcode" )) {
111
+ if (Files .probeContentType (Paths .get (bcFile )).contains (LLVM_IR_BITCODE )) {
110
112
logV ("library input:" , bcFile );
111
113
addFile (bcFile );
112
114
} else {
@@ -133,7 +135,7 @@ void addFile(String f) {
133
135
try {
134
136
// symbols defined up to here
135
137
ProcessBuilder nm = new ProcessBuilder ();
136
- nm .command ("llvm-nm" , "-g" , "--defined-only" , f );
138
+ nm .command (LLVM_NM , "-g" , "--defined-only" , f );
137
139
nm .redirectInput (Redirect .INHERIT );
138
140
nm .redirectError (Redirect .INHERIT );
139
141
nm .redirectOutput (Redirect .PIPE );
@@ -153,7 +155,7 @@ void addFile(String f) {
153
155
undefinedSymbols .removeAll (definedSymbols );
154
156
155
157
// add symbols undefined now
156
- nm .command ("llvm-nm" , "-u" , f );
158
+ nm .command (LLVM_NM , "-u" , f );
157
159
nm .redirectInput (Redirect .INHERIT );
158
160
nm .redirectError (Redirect .INHERIT );
159
161
nm .redirectOutput (Redirect .PIPE );
@@ -235,13 +237,18 @@ private Collection<? extends String> arMembers(String path) throws IOException,
235
237
extractAr .start ().waitFor ();
236
238
237
239
// 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
240
247
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 )) {
242
249
HashSet <String > definedHere = new HashSet <>();
243
250
ProcessBuilder nm = new ProcessBuilder ();
244
- nm .command ("llvm-nm" , "-g" , "--defined-only" , f );
251
+ nm .command (LLVM_NM , "-g" , "--defined-only" , f );
245
252
nm .redirectInput (Redirect .INHERIT );
246
253
nm .redirectError (Redirect .INHERIT );
247
254
nm .redirectOutput (Redirect .PIPE );
0 commit comments