Skip to content

Commit

Permalink
turn on libatomic for FreeBSD (#23901)
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy authored and ararslan committed Dec 12, 2017
1 parent 7708eb1 commit a8054ed
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,12 @@ void NotifyDebugger(jit_code_entry *JITCodeEntry)
}
// ------------------------ END OF TEMPORARY COPY FROM LLVM -----------------

#if defined(_OS_LINUX_) || defined(_OS_WINDOWS_)
#if defined(_OS_LINUX_) || defined(_OS_WINDOWS_) || defined(_OS_FREEBSD_)
// Resolve non-lock free atomic functions in the libatomic library.
// This is the library that provides support for c11/c++11 atomic operations.
static uint64_t resolve_atomic(const char *name)
{
#if defined(_OS_LINUX_)
#if defined(_OS_LINUX_) || defined(_OS_FREEBSD_)
static const char *const libatomic = "libatomic";
#elif defined(_OS_WINDOWS_)
static const char *const libatomic = "libatomic-1";
Expand Down Expand Up @@ -579,7 +579,7 @@ void JuliaOJIT::addModule(std::unique_ptr<Module> M)
// Step 2: Search the program symbols
if (uint64_t addr = SectionMemoryManager::getSymbolAddressInProcess(Name))
return JL_SymbolInfo(addr, JITSymbolFlags::Exported);
#if defined(_OS_LINUX_) || defined(_OS_WINDOWS_)
#if defined(_OS_LINUX_) || defined(_OS_WINDOWS_) || defined(_OS_FREEBSD_)
if (uint64_t addr = resolve_atomic(Name.c_str()))
return JL_SymbolInfo(addr, JITSymbolFlags::Exported);
#endif
Expand Down
27 changes: 27 additions & 0 deletions test/threads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,30 @@ function test_nested_loops()
end
end
test_nested_loops()

@testset "libatomic" begin
prog = """
using Base.Threads
function unaligned_setindex!(x::Atomic{UInt128}, v::UInt128)
Base.llvmcall(\"\"\"
%ptr = inttoptr i$(Sys.WORD_SIZE) %0 to i128*
store atomic i128 %1, i128* %ptr release, align 8
ret void
\"\"\", Void, Tuple{Ptr{UInt128}, UInt128}, unsafe_convert(Ptr{UInt128}, x), v)
end
code_native(STDOUT, unaligned_setindex!, Tuple{Atomic{UInt128}, UInt128})
"""

mktempdir() do dir
file = joinpath(dir, "test23901.jl")
write(file, prog)
run(pipeline(ignorestatus(`$(Base.julia_cmd()) --startup-file=no $file`),
stdout=joinpath(dir, "out.txt"),
stderr=joinpath(dir, "err.txt"),
append=false))
out = readchomp(joinpath(dir, "out.txt"))
err = readchomp(joinpath(dir, "err.txt"))
@test contains(out, "libat_store") || contains(out, "atomic_store")
@test !contains(err, "__atomic_store")
end
end

0 comments on commit a8054ed

Please sign in to comment.