Skip to content

Commit

Permalink
Add cc's search paths to Unix dynamic library loader (#15127)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored Oct 28, 2024
1 parent 0e1018f commit be1e1e5
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 50 deletions.
7 changes: 0 additions & 7 deletions spec/std/llvm/aarch64_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::ABI::AArch64
{% skip_file %}
{% end %}

require "llvm"

{% if LibLLVM::BUILT_TARGETS.includes?(:aarch64) %}
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/arm_abi_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::ABI::ARM
{% skip_file %}
{% end %}

require "llvm"

{% if LibLLVM::BUILT_TARGETS.includes?(:arm) %}
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/avr_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::ABI::AVR
{% skip_file %}
{% end %}

require "llvm"

{% if LibLLVM::BUILT_TARGETS.includes?(:avr) %}
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/llvm_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM
{% skip_file %}
{% end %}

require "llvm"

describe LLVM do
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/type_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::Type
{% skip_file %}
{% end %}

require "llvm"

describe LLVM::Type do
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/x86_64_abi_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::ABI::X86_64
{% skip_file %}
{% end %}

require "llvm"

{% if LibLLVM::BUILT_TARGETS.includes?(:x86) %}
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/x86_abi_spec.cr
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
{% skip_file if flag?(:win32) %} # 32-bit windows is not supported

require "spec"

{% if flag?(:interpreted) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::ABI::X86
{% skip_file %}
{% end %}

require "llvm"

{% if LibLLVM::BUILT_TARGETS.includes?(:x86) %}
Expand Down
31 changes: 30 additions & 1 deletion src/compiler/crystal/loader/unix.cr
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ class Crystal::Loader
parser.unknown_args do |args, after_dash|
file_paths.concat args
end

# although flags starting with `-Wl,` appear in `args` above, this is
# still called by `OptionParser`, so we assume it is fine to ignore these
# flags
parser.invalid_option do |arg|
unless arg.starts_with?("-Wl,")
raise LoadError.new "Not a recognized linker flag: #{arg}"
end
end
end

search_paths = extra_search_paths + search_paths
Expand Down Expand Up @@ -162,6 +171,10 @@ class Crystal::Loader
read_ld_conf(default_search_paths)
{% end %}

cc_each_library_path do |path|
default_search_paths << path
end

{% if flag?(:darwin) %}
default_search_paths << "/usr/lib"
default_search_paths << "/usr/local/lib"
Expand All @@ -179,7 +192,7 @@ class Crystal::Loader
default_search_paths << "/usr/lib"
{% end %}

default_search_paths
default_search_paths.uniq!
end

def self.read_ld_conf(array = [] of String, path = "/etc/ld.so.conf") : Nil
Expand All @@ -201,4 +214,20 @@ class Crystal::Loader
end
end
end

def self.cc_each_library_path(& : String ->) : Nil
search_dirs = begin
`#{Crystal::Compiler::DEFAULT_LINKER} -print-search-dirs`
rescue IO::Error
return
end

search_dirs.each_line do |line|
if libraries = line.lchop?("libraries: =")
libraries.split(Process::PATH_DELIMITER) do |path|
yield File.expand_path(path)
end
end
end
end
end

0 comments on commit be1e1e5

Please sign in to comment.