Skip to content

Commit

Permalink
Support linking to LLVM 3.5.
Browse files Browse the repository at this point in the history
When using LLVM 3.5 one now has to include the --system-libs option when
linking. This option includes flags for linking to zlib and other libraries
required by LLVM. Previously this would be handled by other flags such as
--ldflags. From what I can gather the order is also important: system-libs has
to come after ldflags.

To implement this I've added the config option llvm_ldflags and moved generating
these flags to the configure script (instead of rakelib/blueprint.rb). This
change also fixed a small Windows issue that I noticed: the blueprint code would
call #sub on the ldlags Array, but that method only exists on the String class.

Worth noting, Julia seems to have had the same problem with LLVM 3.5:
JuliaLang/julia#7696.
Yorick Peterse committed Sep 21, 2014
1 parent 25554dc commit a724e8c
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -69,6 +69,7 @@ class Configure
@llvm_shared = false
@llvm_shared_objs = nil
@llvm_cxxflags = ""
@llvm_ldflags = ""

@llvm_version = "3.4.2"
@llvm_api_version = 304
@@ -931,9 +932,20 @@ int main() { LLVMContext &Context = getGlobalContext(); }
end

def check_llvm_flags
flags = '--ldflags'

if @llvm_api_version >= 305
@llvm_cxxflags << " -std=c++11"

# Starting with LLVM 3.5 the --system-libs option is required in order to
# link against libraries such as zlib. Prior to 3.5 this was handled by
# --ldflags.
flags << ' --system-libs'
end

# Generate the actual flags. For whatever reason llvm-config also includes
# newlines in the output, so lets get rid of those while we're at it.
@llvm_ldflags = `#{@llvm_configure} #{flags}`.strip.gsub("\n", ' ')
end

def env(which)
@@ -1747,6 +1759,7 @@ int main() { return tgetnum(""); }
:llvm_version => @llvm_version,
:llvm_shared_objs => @llvm_shared_objs,
:llvm_cxxflags => @llvm_cxxflags,
:llvm_ldflags => @llvm_ldflags,
:cc => @cc,
:cxx => @cxx,
:ldshared => @ldshared,
5 changes: 3 additions & 2 deletions rakelib/blueprint.rb
Original file line number Diff line number Diff line change
@@ -234,7 +234,7 @@

flags << "-DENABLE_LLVM"

ldflags = `#{conf} --ldflags`.strip.split(/\s+/)
ldflags = Rubinius::BUILD_CONFIG[:llvm_ldflags]

if Rubinius::BUILD_CONFIG[:llvm_shared_objs]
objects = Rubinius::BUILD_CONFIG[:llvm_shared_objs]
@@ -253,7 +253,8 @@

gcc.cflags.concat flags
gcc.ldflags.concat objects
gcc.ldflags.concat ldflags

gcc.ldflags << ldflags
when :no
# nothing, not using LLVM
else

0 comments on commit a724e8c

Please sign in to comment.