Skip to content

Commit 48461df

Browse files
committed
Merge pull request #13 from SRI-CSL/master
Port to darwin
2 parents 00d64a4 + da7b0cc commit 48461df

File tree

6 files changed

+386
-143
lines changed

6 files changed

+386
-143
lines changed

NOTES.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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"
20+
21+
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
57+
58+

README-freeBSD.md

Lines changed: 74 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
1-
Steps to build bitcode version of FreeBSD 10.0 world and kernel
2-
-----------------------------------------------
1+
# Steps to build bitcode version of FreeBSD 10.0 world and kernel
32

43
The following instructions have been tested with FreeBSD 10.0 amd64.
54

6-
-- Prerequisites: --------------------------------------------------------------
5+
## Prerequisites
76

8-
1. FreeBSD
7+
### 1. FreeBSD
98

109
The ideal way to start is with a clean install of FreeBSD 10.0 with
1110
sources installed. The simplest way to do this is to install from the
1211
Release 10.0 ISO image and and on the "Distribution Select" screen
1312
select just the following:
1413

15-
[*] ports Ports tree
16-
[*] src System source code
14+
[*] ports Ports tree
15+
[*] src System source code
1716

1817
If you are on an existing system that has either an old version of the
1918
source tree or is missing source, you can follow the instructions in the
2019
FreeBSD Handbook Chapter 24 to get the relevant sources.
2120

22-
2. Necessary ports
21+
### 2. Necessary ports
2322

2423
Upgrade the ports collection (as 'root'):
2524

26-
su -
27-
portsnap fetch
28-
portsnap extract
29-
cd /usr/ports/ports-mgmt/portupgrade
30-
make -DBATCH install clean
31-
portupgrade -a --batch
25+
su -
26+
portsnap fetch
27+
portsnap extract
28+
cd /usr/ports/ports-mgmt/portupgrade
29+
make -DBATCH install clean
30+
portupgrade -a --batch
3231

3332
Install the following ports using the BSD port tree:
3433

35-
bash git subversion python27 sudo wget
34+
bash git subversion python27 sudo wget
3635

3736
(See the FreeBSD Handbook Chapter 5 for instructions.)
3837
The quick way to do this is:
3938

40-
su -
41-
cd /usr/ports
42-
cd shells/bash && make -DBATCH install clean && \
39+
su -
40+
cd /usr/ports
41+
cd shells/bash && make -DBATCH install clean && \
4342
cd ../../devel/git && make -DBATCH install clean && \
4443
cd ../../devel/subversion && make -DBATCH install clean && \
4544
cd ../../security/sudo && make -DBATCH install clean && \
@@ -49,7 +48,7 @@ The quick way to do this is:
4948

5049
Below we assume the shell being used is bash, that is:
5150

52-
chsh -s /usr/local/bin/bash
51+
chsh -s /usr/local/bin/bash
5352

5453
has been run. If you want to use another shell, replace bash-isms like
5554
'export' with the appropriate equivalent.
@@ -58,101 +57,106 @@ We suggest installing 'sudo' and setting up your account as a sudoer, to
5857
make installing programs easier. You can do this, or modify the commands
5958
that use 'sudo' below.
6059

61-
3. LLVM and Clang 3.3
60+
### 3. LLVM and Clang 3.3
6261

6362
Install LLVM and Clang version 3.3. (These instructions adapted from
6463
http://llvm.org/docs/GettingStarted.html) Decide where you want to
6564
install LLVM. If you have 'root' access, you can use the default
6665
'/usr/local', though any location is fine. You may then wish to add this
6766
to your shell startup (in '~/.profile' for bash):
6867

69-
export LLVM_HOME=/usr/local/llvm-3.3
68+
export LLVM_HOME=/usr/local/llvm-3.3
7069

7170
Get LLVM and Clang version 3.5:
7271

73-
svn co http://llvm.org/svn/llvm-project/llvm/branches/release_33 llvm
74-
cd llvm/tools
75-
svn co http://llvm.org/svn/llvm-project/cfe/branches/release_33 clang
76-
cd ../projects
77-
svn co http://llvm.org/svn/llvm-project/compiler-rt/branches/release_33 compiler-rt
78-
cd ../..
72+
svn co http://llvm.org/svn/llvm-project/llvm/branches/release_33 llvm
73+
cd llvm/tools
74+
svn co http://llvm.org/svn/llvm-project/cfe/branches/release_33 clang
75+
cd ../projects
76+
svn co http://llvm.org/svn/llvm-project/compiler-rt/branches/release_33 compiler-rt
77+
cd ../..
7978

8079
Now finish the build and install:
8180

82-
cd llvm
83-
mkdir build
84-
cd build
85-
../configure --prefix=$LLVM_HOME --enable-assertions \
86-
--enable-targets=host-only --enable-optimized
87-
gmake
88-
sudo gmake install
81+
cd llvm
82+
mkdir build
83+
cd build
84+
../configure --prefix=$LLVM_HOME --enable-assertions \
85+
--enable-targets=host-only --enable-optimized
86+
gmake
87+
sudo gmake install
8988

9089
Note that the FreeBSD 10.0 base includes Clang 3.3 (but does not include
9190
the complete LLVM framework, in particular llvm-link is not included).
9291

9392
So to make life easier, so that extract-bc can find it do:
9493

95-
sudo ln -s $LLVM_HOME/bin/llvm-link /usr/bin/llvm-link
94+
sudo ln -s $LLVM_HOME/bin/llvm-link /usr/bin/llvm-link
9695

9796

98-
1. Download SRI-modified version of WLLVM.
97+
### 4. Download whole-program-wllvm.
9998

100-
> cd ${HOME}
101-
> git clone https://github.com/SRI-CSL/whole-program-llvm
99+
cd ${HOME}
100+
git clone https://github.com/travitch/whole-program-llvm
102101

103-
2. Create the hooks for interposing on compiler calls.
102+
Create the hooks for interposing on compiler calls.
104103

105-
> cd ${HOME}
106-
> mkdir ${HOME}/wllvm.bin
107-
> cd wllvm.bin
108-
> ln -s ${HOME}/whole-program-llvm/wllvm cc
109-
> ln -s ${HOME}/whole-program-llvm/wllvm++ c++
110-
> ln -s ${HOME}/whole-program-llvm/wllvm clang
111-
> ln -s ${HOME}/whole-program-llvm/wllvm++ clang++
112-
this next one is a hack (make buildworld doesn't find python with /usr/bin/env without it)
113-
> ln -s /usr/local/bin/python python
104+
cd ${HOME}
105+
mkdir ${HOME}/wllvm.bin
106+
cd wllvm.bin
107+
ln -s ${HOME}/whole-program-llvm/wllvm cc
108+
ln -s ${HOME}/whole-program-llvm/wllvm++ c++
109+
ln -s ${HOME}/whole-program-llvm/wllvm clang
110+
ln -s ${HOME}/whole-program-llvm/wllvm++ clang++
114111

115-
3. Insert the hooks into the build path.
112+
This next one is a hack (make buildworld doesn't find python with /usr/bin/env without it)
116113

117-
> diff /usr/src/Makefile.inc1 Makefile.inc1.original
114+
ln -s /usr/local/bin/python python
115+
116+
### 5. Insert the hooks into the build path.
117+
118+
```
119+
diff /usr/src/Makefile.inc1 Makefile.inc1.original
118120
180c180
119-
< BPATH= ${HOME}/wllvm.bin:${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/usr/games:${WORLDTMP}/legacy/bin
121+
BPATH= ${HOME}/wllvm.bin:${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/usr/games:${WORLDTMP}/legacy/bin
120122
---
121-
> BPATH= ${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/usr/games:${WORLDTMP}/legacy/bin
123+
BPATH= ${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/usr/games:${WORLDTMP}/legacy/bin
124+
```
122125

123-
4. If the build location doesn't exist, create it.
126+
## Building the Puppy
124127

125-
> mkdir ${HOME}/build.world
128+
If the build location doesn't exist, create it.
126129

127-
5. Configure the environment for the build.
130+
mkdir ${HOME}/build.world
128131

129-
> export MAKEOBJDIRPREFIX=${HOME}/build.world
130-
> export LLVM_COMPILER=clang
131-
> export LLVM_COMPILER_PATH=/usr/bin
132-
> export WLLVM_OUTPUT=DEBUG
132+
Configure the environment for the build.
133133

134-
6. Start the build.
134+
export MAKEOBJDIRPREFIX=${HOME}/build.world
135+
export LLVM_COMPILER=clang
136+
export LLVM_COMPILER_PATH=/usr/bin
137+
export WLLVM_OUTPUT=DEBUG
135138

136-
> cd /usr/src
137-
> make buildworld
139+
Start the build.
138140

139-
7. Once that succeeds build the kernel
141+
cd /usr/src
142+
make buildworld
140143

141-
> make buildkernel
144+
Once that succeeds build the kernel
142145

146+
make buildkernel
143147

144-
8. extract the bitcode:
148+
Extract the bitcode:
145149

146150

147-
cd ${MAKEOBJDIRPREFIX}/usr/src/sys/GENERIC
151+
cd ${MAKEOBJDIRPREFIX}/usr/src/sys/GENERIC
148152

149-
> ${HOME}/whole-program-llvm/extract-bc kernel
153+
${HOME}/whole-program-llvm/extract-bc kernel
150154

151-
> nm kernel | wc
152-
53140 159418 2421852
155+
nm kernel | wc
156+
53140 159418 2421852
153157

154-
> ${LLVM_HOME}/bin/llvm-nm kernel.bc | wc
155-
50664 101328 1910997
158+
${LLVM_HOME}/bin/llvm-nm kernel.bc | wc
159+
50664 101328 1910997
156160

157161
We are working on seeing if we can get these numbers to match.
158162
But suspect their is some assembler causing this difference.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ Example building bitcode archive
8282
# Produces src/LinearMath/libLinearMath.bca
8383
extract-bc src/LinearMath/libLinearMath.a
8484

85+
Example building an Operating System
86+
================================
87+
88+
To see how to build freeBSD 10.0 from scratch check out the guide
89+
[here.](../master/README-freeBSD.md)
90+
8591
Debugging
8692
=========
8793

0 commit comments

Comments
 (0)