Skip to content
Browse files

Recommend compiling with PIC consistently.

While shared objects with non-PIC code work on some architectures
(notably x86), unless code is always PIC on that arch (not true for x86)
doing so requires runtime relocations, which prevents the object
actually being shared, and means such segments can't be marked as
read-only.
  • Loading branch information...
1 parent bdb45ca commit de7ed84f77d2e27b5fdea1ad0774994df2720caa @ojwb ojwb committed Feb 21, 2014
Showing with 29 additions and 27 deletions.
  1. +3 −4 Doc/Manual/Java.html
  2. +2 −2 Doc/Manual/Lua.html
  3. +2 −2 Doc/Manual/Perl5.html
  4. +14 −6 Doc/Manual/Ruby.html
  5. +1 −1 Doc/Manual/SWIGPlus.html
  6. +1 −6 Doc/Manual/Scripting.html
  7. +6 −6 Doc/Manual/Tcl.html
View
7 Doc/Manual/Java.html
@@ -332,8 +332,8 @@
<div class="code"><pre>
$ swig -java example.i
-$ gcc -c example_wrap.c -I/usr/java/include -I/usr/java/include/solaris
-$ gcc -c example.c
+$ gcc -fPIC -c example_wrap.c -I/usr/java/include -I/usr/java/include/solaris
+$ gcc -fPIC -c example.c
$ ld -G example_wrap.o example.o -o libexample.so
</pre></div>
@@ -493,8 +493,7 @@
<div class="code"><pre>
% swig -c++ -java example.i
% g++ -c -fpic example.cxx
-% g++ -c -fpic example_wrap.cxx -I/usr/java/j2sdk1.4.1/include -I/usr/java/
-j2sdk1.4.1/include/linux
+% g++ -c -fpic example_wrap.cxx -I/usr/java/j2sdk1.4.1/include -I/usr/java/j2sdk1.4.1/include/linux
% g++ -shared example.o example_wrap.o -o libexample.so
</pre></div>
View
4 Doc/Manual/Lua.html
@@ -240,8 +240,8 @@
</p>
<div class="shell"><pre>
$ swig -lua example.i -o example_wrap.c
-$ gcc -I/usr/include/lua -c example_wrap.c -o example_wrap.o
-$ gcc -c example.c -o example.o
+$ gcc -fPIC -I/usr/include/lua -c example_wrap.c -o example_wrap.o
+$ gcc -fPIC -c example.c -o example.o
$ gcc -shared -I/usr/include/lua -L/usr/lib/lua example_wrap.o example.o -o example.so
</pre></div>
<p>
View
4 Doc/Manual/Perl5.html
@@ -493,8 +493,8 @@
<div class="code"><pre>
$ swig -c++ -perl example.i
-$ CC -c example.cxx
-$ CC -c example_wrap.cxx -I/usr/lib/perl/5.14/i386-linux/CORE
+$ CC -Kpic -c example.cxx
+$ CC -Kpic -c example_wrap.cxx -I/usr/lib/perl/5.14/i386-linux/CORE
$ CC -shared example.o example_wrap.o -o example.so <b>-lCrun</b>
</pre></div>
View
20 Doc/Manual/Ruby.html
@@ -259,14 +259,22 @@
<div class="code shell">
<pre>$ swig -ruby example.i
-$ gcc -c example.c
-$ gcc -c example_wrap.c -I/usr/local/lib/ruby/1.6/i686-linux
+$ gcc -O2 -fPIC -c example.c
+$ gcc -O2 -fPIC -c example_wrap.c -I/usr/local/lib/ruby/1.6/i686-linux
$ gcc -shared example.o example_wrap.o -o example.so
</pre>
</div>
-<p> For other platforms it may be necessary to compile with the <tt>-fPIC</tt>
-option to generate position-independent code. If in doubt, consult the
+<p>
+The -fPIC option tells GCC to generate position-independent code (PIC)
+which is required for most architectures (it's not vital on x86, but
+still a good idea as it allows code pages from the library to be shared between
+processes). Other compilers may need a different option specified instead of
+-fPIC.
+</p>
+
+<p>
+If in doubt, consult the
manual pages for your compiler and linker to determine the correct set
of options. You might also check the <a href="http://www.dabeaz.com/cgi-bin/wiki.pl">SWIG Wiki</a>
for additional information. </p>
@@ -325,8 +333,8 @@
<div class="code shell">
<pre>
$ swig -c++ -ruby example.i
-$ g++ -c example.cxx
-$ g++ -c example_wrap.cxx -I/usr/local/lib/ruby/1.6/i686-linux
+$ g++ -fPIC -c example.cxx
+$ g++ -fPIC -c example_wrap.cxx -I/usr/local/lib/ruby/1.6/i686-linux
$ g++ -shared example.o example_wrap.o -o example.so
</pre>
</div>
View
2 Doc/Manual/SWIGPlus.html
@@ -216,7 +216,7 @@
<div class="shell">
<pre>
$ swig -c++ -tcl example.i
-$ c++ -c example_wrap.cxx
+$ c++ -fPIC -c example_wrap.cxx
$ c++ example_wrap.o $(OBJS) -o example.so
</pre>
</div>
View
7 Doc/Manual/Scripting.html
@@ -368,17 +368,12 @@
<div class="shell"><pre>
# Build a shared library for Solaris
-gcc -c example.c example_wrap.c -I/usr/local/include
+gcc -fpic -c example.c example_wrap.c -I/usr/local/include
ld -G example.o example_wrap.o -o example.so
# Build a shared library for Linux
gcc -fpic -c example.c example_wrap.c -I/usr/local/include
gcc -shared example.o example_wrap.o -o example.so
-
-# Build a shared library for Irix
-gcc -c example.c example_wrap.c -I/usr/local/include
-ld -shared example.o example_wrap.o -o example.so
-
</pre></div>
<p>
View
12 Doc/Manual/Tcl.html
@@ -139,8 +139,8 @@
<div class="code"><pre>
$ swig -tcl example.i
-$ gcc -c example.c
-$ gcc -c example_wrap.c -I/usr/local/include
+$ gcc -fPIC -c example.c
+$ gcc -fPIC -c example_wrap.c -I/usr/local/include
$ gcc -shared example.o example_wrap.o -o example.so
</pre></div>
@@ -374,8 +374,8 @@
<div class="code"><pre>
% swig -c++ -tcl example.i
-% g++ -c example.cxx
-% g++ -c example_wrap.cxx -I/usr/local/include
+% g++ -fPIC -c example.cxx
+% g++ -fPIC -c example_wrap.cxx -I/usr/local/include
% g++ -shared example.o example_wrap.o -o example.so
</pre></div>
@@ -387,8 +387,8 @@
<div class="code"><pre>
% swig -c++ -tcl example.i
-% CC -c example.cxx
-% CC -c example_wrap.cxx -I/usr/local/include
+% CC -KPIC -c example.cxx
+% CC -KPIC -c example_wrap.cxx -I/usr/local/include
% CC -G example.o example_wrap.o -L/opt/SUNWspro/lib -o example.so -lCrun
</pre></div>

0 comments on commit de7ed84

Please sign in to comment.
Something went wrong with that request. Please try again.