Skip to content

Commit f4d0a5d

Browse files
committed
2 parents 1f2df9c + e14a5b7 commit f4d0a5d

File tree

3 files changed

+32
-73
lines changed

3 files changed

+32
-73
lines changed

NOTES.txt

Lines changed: 19 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,23 @@
1-
WARNING:Did not recognize the compiler flag "-m32"
2-
WARNING:Did not recognize the compiler flag "-march=i686"
3-
WARNING:Did not recognize the compiler flag "-B/home/iam/world/usr/src/lib32/usr/lib32"
4-
WARNING:Did not recognize the compiler flag "-mpreferred-stack-boundary=2"
5-
WARNING:Did not recognize the compiler flag "-mno-align-long-strings"
6-
WARNING:Did not recognize the compiler flag "-mrtd"
7-
WARNING:Did not recognize the compiler flag "-mregparm=3"
8-
WARNING:Did not recognize the compiler flag "-mstack-alignment=8"
9-
WARNING:Did not recognize the compiler flag "-mllvm"
10-
WARNING:Did not recognize the compiler flag "-inline-threshold=3"
11-
WARNING:Did not recognize the compiler flag "-enable-load-pre=false"
12-
WARNING:Did not recognize the compiler flag "-mllvm"
13-
WARNING:Did not recognize the compiler flag "-simplifycfg-dup-ret"
14-
WARNING:Did not recognize the compiler flag "-march=i386"
15-
WARNING:Did not recognize the compiler flag "cat.lo" ....
16-
WARNING:Did not recognize the compiler flag "-Ttext"
17-
WARNING:Did not recognize the compiler flag "0x600"
18-
WARNING:Did not recognize the compiler flag "-m"
19-
WARNING:Did not recognize the compiler flag "elf_i386_fbsd"
201

2+
"-m32"
3+
"-march=i686"
4+
"-B/home/iam/world/usr/src/lib32/usr/lib32"
5+
"-mpreferred-stack-boundary=2"
6+
"-mno-align-long-strings"
7+
"-mrtd"
8+
"-mregparm=3"
9+
"-mstack-alignment=8"
10+
"-mllvm"
11+
"-inline-threshold=3"
12+
"-enable-load-pre=false"
13+
"-mllvm"
14+
"-simplifycfg-dup-ret"
15+
"-march=i386"
16+
"cat.lo" ....
17+
"-Ttext"
18+
"0x600"
19+
"-m"
20+
"elf_i386_fbsd"
2121

22-
Darwin linker flags:
23-
24-
WARNING:Did not recognize the compiler flag "-dynamiclib"
25-
WARNING:Did not recognize the compiler flag "-current_version"
26-
WARNING:Did not recognize the compiler flag "2.2.2"
27-
WARNING:Did not recognize the compiler flag "-compatibility_version"
28-
WARNING:Did not recognize the compiler flag "2.2.0"
29-
30-
Attempt to attach bitcode stuff on MacOS using ld:
31-
32-
ld -r <file.o> -sectcreate __LLVM __llvm_bc <tmpfile> -o <file.o>
33-
34-
This works (it adds a new section called __llvm_bc in a new __LLVM
35-
segment), but the 'ld -r' part may have bad side effects. For example
36-
if the <file.o> is produced with -fvisibility=hidden then calling
37-
ld -r <file.o> converts the extern symbols into local symbols.
38-
39-
Workaround for now: give a warning if we see -fvisibility=hidden on
40-
the Mac.
41-
42-
43-
44-
TODO: extract-bc for MacOS
45-
46-
To extract bitcode from binaries, objects, or library files on Darwin:
47-
48-
otool -X -s __LLVM __llvm_bc yices_sat | xxd -r
49-
50-
Explanations:
51-
52-
otool -s __LLVM __llvm_bc file extracts and display the section we care about
53-
54-
flag -X removes some useless headers we don't want
55-
56-
xxd -r converts the hexdump to ASCII list of file names
5722

5823

driver/utils.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
118118
'-m3dnow' : (0, ArgumentListFilter.compileUnaryCallback),
119119
'-mno-3dnow' : (0, ArgumentListFilter.compileUnaryCallback),
120120

121+
121122
# Preprocessor assertion
122123
'-A' : (1, ArgumentListFilter.compileBinaryCallback),
123124
'-D' : (1, ArgumentListFilter.compileBinaryCallback),
@@ -192,7 +193,8 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
192193
'-current_version' : (1, ArgumentListFilter.linkBinaryCallback),
193194
'-compatibility_version' : (1, ArgumentListFilter.linkBinaryCallback),
194195

195-
# bd: need to warn the darwin user that these flags will rain on their parade
196+
#
197+
# BD: need to warn the darwin user that these flags will rain on their parade
196198
# (the Darwin ld is a bit single minded)
197199
#
198200
# 1) compilation with -fvisibility=hidden causes trouble when we try to
@@ -202,7 +204,9 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
202204
# 2) all stripping commands (e.g., -dead_strip) remove the __LLVM segment after
203205
# linking
204206
#
205-
'-fvisibility=hidden' : (0, ArgumentListFilter.darwinWarningCompileUnaryCallback),
207+
# Update: found a fix for problem 1: add flag -keep_private_externs when
208+
# calling ld -r.
209+
#
206210
'-Wl,-dead_strip' : (0, ArgumentListFilter.darwinWarningLinkUnaryCallback),
207211

208212
}
@@ -333,13 +337,6 @@ def linkUnaryCallback(self, flag):
333337
def compileUnaryCallback(self, flag):
334338
self.compileArgs.append(flag)
335339

336-
def darwinWarningCompileUnaryCallback(self, flag):
337-
if sys.platform.startswith('darwin'):
338-
_logger.warning('The flag "{0}" cannot be used with this tool'.format(flag))
339-
sys.exit(1)
340-
else:
341-
self.compileArgs.append(flag)
342-
343340
def darwinWarningLinkUnaryCallback(self, flag):
344341
if sys.platform.startswith('darwin'):
345342
_logger.warning('The flag "{0}" cannot be used with this tool'.format(flag))
@@ -490,7 +487,7 @@ def attachBitcodePathToObject(bcPath, outFileName):
490487

491488
# Now write our bitcode section
492489
if (sys.platform.startswith('darwin')):
493-
objcopyCmd = ['ld', '-r', outFileName, '-sectcreate', darwinSegmentName, darwinSectionName, f.name, '-o', outFileName]
490+
objcopyCmd = ['ld', '-r', '-keep_private_externs', outFileName, '-sectcreate', darwinSegmentName, darwinSectionName, f.name, '-o', outFileName]
494491
else:
495492
objcopyCmd = ['objcopy', '--add-section', '{0}={1}'.format(elfSectionName, f.name), outFileName]
496493
orc = 0
@@ -683,8 +680,8 @@ def linkFiles(builder, objectFiles):
683680
af = builder.getBitcodeArglistFilter()
684681
outputFile = af.getOutputFilename()
685682
cc = builder.getCompiler()
686-
cc.extend(af.objectFiles)
687683
cc.extend(objectFiles)
684+
cc.extend(af.objectFiles)
688685
cc.extend(af.linkArgs)
689686
cc.extend(['-o', outputFile])
690687
proc = Popen(cc)

extract-bc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,9 @@ def handleExecutable(inputFile, outputFile, extractor, llvmLinker):
144144
if outputFile == None:
145145
outputFile = inputFile + '.' + moduleExtension
146146

147-
linkCmd = [ llvmLinker, '-o', outputFile ]
148-
149-
if verboseFlag:
150-
linkCmd.insert(1, '-v')
147+
linkCmd = [ llvmLinker, '-v' ] if verboseFlag else [ llvmLinker ]
148+
149+
linkCmd.extend(['-o', outputFile ])
151150

152151
linkCmd.extend([x for x in fileNames if x != ''])
153152
logging.info('Writing output to {0}'.format(outputFile))
@@ -164,8 +163,6 @@ def handleArchive(inputFile, outputFile, arCmd, fileType, extractor, llvmArchive
164163
originalDir = os.getcwd() # This will be the destination
165164

166165
arCmd.append(inputFile);
167-
if verboseFlag:
168-
arCmd.insert(1, '-v')
169166

170167
# Make temporary directory to extract objects to
171168
tempDir = ''
@@ -344,7 +341,7 @@ def process_file_unix(inputFile, outputFile, llvmLinker, llvmArchiver):
344341
logging.debug('Detected file type is {0}'.format(FileType.revMap[ft]))
345342

346343
extractor = extract_section_linux
347-
arCmd = ['ar','x']
344+
arCmd = ['ar', 'xv'] if verboseFlag else ['ar', 'x']
348345
ofileType = FileType.ELF_OBJECT
349346

350347
if ft == FileType.ELF_EXECUTABLE or ft == FileType.ELF_SHARED:
@@ -364,7 +361,7 @@ def process_file_darwin(inputFile, outputFile, llvmLinker, llvmArchiver):
364361
logging.debug('Detected file type is {0}'.format(FileType.revMap[ft]))
365362

366363
extractor = extract_section_darwin
367-
arCmd = ['ar','-x']
364+
arCmd = ['ar', '-x', '-v'] if verboseFlag else ['ar', '-x']
368365
ofileType = FileType.MACH_OBJECT
369366

370367
if ft == FileType.MACH_EXECUTABLE or ft == FileType.MACH_SHARED:

0 commit comments

Comments
 (0)