Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ USE_SYSTEM_ZSTD:=0
USE_SYSTEM_P7ZIP:=0
USE_SYSTEM_LLD:=0

# Link libjulia-internal with static libgcc and libstdc++
USE_RT_STATIC_LIBGCC:=1
USE_RT_STATIC_LIBSTDCXX:=1

# Link to the LLVM shared library
USE_LLVM_SHLIB := 1

Expand Down Expand Up @@ -97,6 +101,9 @@ WITH_TRACY_CALLSTACKS := 0
# Enable Timing Counts support
WITH_TIMING_COUNTS := 0

# Should --gc-sections/-dead_strip be used to remove unreferenced code?
USE_LINKER_GC:=1

# Prevent picking up $ARCH from the environment variables
ARCH:=

Expand Down Expand Up @@ -932,6 +939,23 @@ JCXXFLAGS += -DUSE_NVTX
JCFLAGS += -DUSE_NVTX
endif

ifneq ($(findstring $(OS),WINNT FreeBSD OpenBSD),)
USE_LINKER_GC := 0
USE_RT_STATIC_LIBGCC := 0
USE_RT_STATIC_LIBSTDCXX := 0
endif

# Linker garbage collection
ifeq ($(USE_LINKER_GC), 1)
ifeq ($(OS), Darwin)
JLDFLAGS += -Wl,-dead_strip
else
JLDFLAGS += -Wl,--gc-sections
JCFLAGS += -ffunction-sections -fdata-sections
JCXXFLAGS += -ffunction-sections -fdata-sections
endif
endif

# ===========================================================================

# Select the cpu architecture to target, or automatically detects the user's compiler
Expand Down
5 changes: 5 additions & 0 deletions cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ $(BUILDDIR)/loader_lib.o: export MSYS2_ARG_CONV_EXCL = -DDEP_LIBS=
$(BUILDDIR)/loader_lib.dbg.obj: export MSYS2_ARG_CONV_EXCL = -DDEP_LIBS=
endif # MSYS2

ifeq ($(USE_RT_STATIC_LIBSTDCXX),1)
SHIPFLAGS += -DRT_STATIC_LIBSTDCXX
DEBUGFLAGS += -DRT_STATIC_LIBSTDCXX
endif # USE_RT_STATIC_LIBSTDCXX

EXE_OBJS := $(BUILDDIR)/loader_exe.o
EXE_DOBJS := $(BUILDDIR)/loader_exe.dbg.obj
LIB_OBJS := $(BUILDDIR)/loader_lib.o
Expand Down
6 changes: 6 additions & 0 deletions cli/loader_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,13 @@ __attribute__((constructor)) void jl_load_libjulia_internal(void) {
// If the probe rejected the system libstdc++ (or didn't find one!)
// just load our bundled libstdc++ as identified by curr_dep;
if (!probe_successful) {
# ifdef RT_STATIC_LIBSTDCXX
// If we have a statically-linked libstdc++, it is ok for
// this to fail.
load_library(curr_dep, lib_dir, 0);
# else
load_library(curr_dep, lib_dir, 1);
# endif
}
#endif
} else if (special_idx == 1) {
Expand Down
9 changes: 9 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ RT_LIBS := $(call whole_archive,$(LIBUV)) $(call whole_archive,$(LIBUTF8PROC)) $
# NB: CG needs uv_mutex_* symbols, but we expect to export them from libjulia-internal
CG_LIBS := $(LIBUNWIND) $(CG_LLVMLINK) $(OSLIBS) $(LIBTRACYCLIENT) $(LIBITTAPI)

ifeq ($(USEGCC),1)
ifeq ($(USE_RT_STATIC_LIBGCC),1)
RT_LIBS += -static-libgcc
endif
ifeq ($(USE_RT_STATIC_LIBSTDCXX),1)
RT_LIBS += -static-libstdc++
endif
endif

ifeq (${USE_THIRD_PARTY_GC},mmtk)
RT_LIBS += $(MMTK_LIB)
CG_LIBS += $(MMTK_LIB)
Expand Down
12 changes: 9 additions & 3 deletions src/cgmemmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ static void *create_shared_map(size_t size, size_t id) JL_NOTSAFEPOINT
return addr;
}

static intptr_t init_shared_map() JL_NOTSAFEPOINT
[[maybe_unused]] static intptr_t init_shared_map() JL_NOTSAFEPOINT
{
anon_hdl = get_anon_hdl();
if (anon_hdl == -1)
Expand Down Expand Up @@ -771,6 +771,7 @@ class SelfMemAllocator : public ROAllocator {
std::pair<std::unique_ptr<ROAllocator>, std::unique_ptr<ROAllocator>>
get_preferred_allocators() JL_NOTSAFEPOINT
{
#if !(defined(_CPU_AARCH64_) || defined(_CPU_RISCV64_))
#ifdef _OS_LINUX_
if (get_self_mem_fd() != -1)
return {std::make_unique<SelfMemAllocator>(false),
Expand All @@ -779,6 +780,7 @@ get_preferred_allocators() JL_NOTSAFEPOINT
if (init_shared_map() != -1)
return {std::make_unique<DualMapAllocator>(false),
std::make_unique<DualMapAllocator>(true)};
#endif
return {};
}

Expand Down Expand Up @@ -959,7 +961,8 @@ class JLJITLinkMemoryManager : public jitlink::JITLinkMemoryManager {
void deallocate(std::vector<FinalizedAlloc> Allocs,
OnDeallocatedFunction OnDeallocated) override
{
jl_unreachable();
// This shouldn't be reachable, but we will get a better error message
// from JITLink if we leak this allocation and fail elsewhere.
}

protected:
Expand Down Expand Up @@ -997,7 +1000,10 @@ class JLJITLinkMemoryManager::InFlightAlloc
public:
InFlightAlloc(JLJITLinkMemoryManager &MM, jitlink::LinkGraph &G) : MM(MM), G(G) {}

void abandon(OnAbandonedFunction OnAbandoned) override { jl_unreachable(); }
void abandon(OnAbandonedFunction OnAbandoned) override {
// This shouldn't be reachable, but we will get a better error message
// from JITLink if we leak this allocation and fail elsewhere.
}

void finalize(OnFinalizedFunction OnFinalized) override
{
Expand Down
55 changes: 23 additions & 32 deletions src/coverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
#include <cstdint>
#include <pthread.h>
#include <string>
#include <fstream>
#include <map>
#include <vector>

#include "llvm-version.h"
#include <llvm/ADT/StringRef.h>
Expand Down Expand Up @@ -137,26 +134,20 @@ static void write_log_data(logdata_t &logData, const char *extension) JL_NOTSAFE
if (!values.empty()) {
if (!jl_isabspath(filename.c_str()))
filename = base + filename;
std::ifstream inf(filename.c_str());
if (!inf.is_open())
FILE *inf = fopen(filename.c_str(), "r");
if (!inf)
continue;
std::string outfile = filename + extension;
std::ofstream outf(outfile.c_str(), std::ofstream::trunc | std::ofstream::out | std::ofstream::binary);
if (outf.is_open()) {
inf.exceptions(std::ifstream::badbit);
outf.exceptions(std::ifstream::failbit | std::ifstream::badbit);
FILE *outf = fopen(outfile.c_str(), "wb");
if (outf) {
char line[1024];
int l = 1;
unsigned block = 0;
while (!inf.eof()) {
inf.getline(line, sizeof(line));
if (inf.fail()) {
if (inf.eof())
break; // no content on trailing line
// Read through lines longer than sizeof(line)
inf.clear();
inf.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
int ret = 0;
while (ret != EOF && (ret = fscanf(inf, "%1023[^\n]", line)) != EOF) {
// Skip n non-newline chars and a single trailing newline
if ((ret = fscanf(inf, "%*[^\n]")) != EOF)
ret = fscanf(inf, "%*1[\n]");
logdata_block *data = NULL;
if (block < values.size()) {
data = values[block];
Expand All @@ -166,32 +157,32 @@ static void write_log_data(logdata_t &logData, const char *extension) JL_NOTSAFE
l = 0;
block++;
}
outf.width(9);
if (value == 0)
outf << '-';
fprintf(outf, " -");
else
outf << (value - 1);
outf.width(0);
outf << " " << line << '\n';
fprintf(outf, "%9" PRIu64, value - 1);
fprintf(outf, " %s\n", line);
line[0] = 0;
}
outf.close();
fclose(outf);
}
inf.close();
fclose(inf);
}
}
}

static void write_lcov_data(logdata_t &logData, const std::string &outfile) JL_NOTSAFEPOINT
{
std::ofstream outf(outfile.c_str(), std::ofstream::ate | std::ofstream::out | std::ofstream::binary);
FILE *outf = fopen(outfile.c_str(), "ab");
if (!outf) return;
//std::string base = std::string(jl_options.julia_bindir);
//base = base + "/../share/julia/base/";
logdata_t::iterator it = logData.begin();
for (; it != logData.end(); it++) {
StringRef filename = it->first();
const SmallVector<logdata_block*, 0> &values = it->second;
if (!values.empty()) {
outf << "SF:" << filename.str() << '\n';
fprintf(outf, "SF:%.*s\n", (int)filename.size(), filename.data());
size_t n_covered = 0;
size_t n_instrumented = 0;
size_t lno = 0;
Expand All @@ -204,7 +195,7 @@ static void write_lcov_data(logdata_t &logData, const std::string &outfile) JL_N
n_instrumented++;
if (cov > 1)
n_covered++;
outf << "DA:" << lno << ',' << (cov - 1) << '\n';
fprintf(outf, "DA:%zu,%" PRIu64 "\n", lno, cov - 1);
}
lno++;
}
Expand All @@ -213,12 +204,12 @@ static void write_lcov_data(logdata_t &logData, const std::string &outfile) JL_N
lno += logdata_blocksize;
}
}
outf << "LH:" << n_covered << '\n';
outf << "LF:" << n_instrumented << '\n';
outf << "end_of_record\n";
fprintf(outf, "LH:%zu\n", n_covered);
fprintf(outf, "LF:%zu\n", n_instrumented);
fprintf(outf, "end_of_record\n");
}
}
outf.close();
fclose(outf);
}

extern "C" JL_DLLEXPORT void jl_write_coverage_data(const char *output) JL_NOTSAFEPOINT
Expand Down
31 changes: 11 additions & 20 deletions src/gc-heap-snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,19 @@
#include "julia_internal.h"
#include "julia_assert.h"

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/DenseMap.h"

#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <set>
#include "llvm/Support/FormatVariadic.h"

using std::string;
using std::set;
using std::ostringstream;
using std::pair;
using std::make_pair;
using llvm::SmallVector;
using llvm::StringMap;
using llvm::DenseMap;
using llvm::StringRef;
using llvm::SmallString;
using llvm::formatv;

// https://stackoverflow.com/a/33799784/751061
void print_str_escape_json(ios_t *stream, StringRef s)
Expand Down Expand Up @@ -422,18 +416,16 @@ static size_t record_pointer_to_gc_snapshot(void *a, size_t bytes, StringRef nam
return val.first->second;
}

static string _fieldpath_for_slot(void *obj, void *slot) JL_NOTSAFEPOINT
static SmallString<128> _fieldpath_for_slot(void *obj, void *slot) JL_NOTSAFEPOINT
{
string res;
SmallString<128> res;
jl_datatype_t *objtype = (jl_datatype_t*)jl_typeof(obj);

while (1) {
int i = gc_slot_to_fieldidx(obj, slot, objtype);

if (jl_is_tuple_type(objtype) || jl_is_namedtuple_type(objtype)) {
ostringstream ss;
ss << "[" << i << "]";
res += ss.str();
res += formatv("[{0}]", i).sstr<8>();
}
else {
jl_svec_t *field_names = jl_field_names(objtype);
Expand Down Expand Up @@ -472,9 +464,8 @@ void _gc_heap_snapshot_record_gc_roots(jl_value_t *root, char *name) JL_NOTSAFEP
void _gc_heap_snapshot_record_finlist(jl_value_t *obj, size_t index) JL_NOTSAFEPOINT
{
auto to_node_idx = record_node_to_gc_snapshot(obj);
ostringstream ss;
ss << "finlist-" << index;
auto edge_label = g_snapshot->names.serialize_if_necessary(g_snapshot->strings, ss.str());
SmallString<16> ss = formatv("finlist-{0}", index);
auto edge_label = g_snapshot->names.serialize_if_necessary(g_snapshot->strings, ss);
_record_gc_just_edge("internal", g_snapshot->_gc_finlist_root_idx, to_node_idx, edge_label);
}

Expand Down Expand Up @@ -536,7 +527,7 @@ void _gc_heap_snapshot_record_array_edge(jl_value_t *from, jl_value_t *to, size_

void _gc_heap_snapshot_record_object_edge(jl_value_t *from, jl_value_t *to, void *slot) JL_NOTSAFEPOINT
{
string path = _fieldpath_for_slot(from, slot);
SmallString<128> path = _fieldpath_for_slot(from, slot);
_record_gc_edge("property", from, to,
g_snapshot->names.serialize_if_necessary(g_snapshot->strings, path));
}
Expand Down
3 changes: 0 additions & 3 deletions src/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "julia.h"
#include "julia_internal.h"

#include <map>
#include <algorithm>

#include "julia_assert.h"
Expand All @@ -25,8 +24,6 @@
#include <dlfcn.h>
#endif

#include <iostream>

// CPU target string is a list of strings separated by `;` each string starts with a CPU
// or architecture name and followed by an optional list of features separated by `,`.
// A "generic" or empty CPU name means the basic required feature set of the target ISA
Expand Down
3 changes: 1 addition & 2 deletions src/runtime_ccall.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// This file is a part of Julia. License is MIT: https://julialang.org/license

#include "llvm-version.h"
#include <map>
#include <string>
#include <llvm/ADT/StringMap.h>
#include <llvm/TargetParser/Host.h>
Expand All @@ -25,7 +24,7 @@ using namespace llvm;
jl_value_t *jl_libdl_dlopen_func JL_GLOBALLY_ROOTED;

// map from user-specified lib names to handles
static std::map<std::string, void*> libMap;
static StringMap<void*> libMap;
static jl_mutex_t libmap_lock;
extern "C"
void *jl_get_library_(const char *f_lib, int throw_err)
Expand Down
Loading