More serious LLVM linking
Some checks failed
CI / ci (MinSizeRel, ubuntu-latest) (push) Failing after 1m8s
CI / ci (RelWithDebInfo, ubuntu-latest) (push) Failing after 1m12s
CI / ci (Release, ubuntu-latest) (push) Failing after 1m10s
CI / ci (Debug, ubuntu-latest) (push) Failing after 2m28s

This commit is contained in:
David Gonzalez Martin 2025-05-29 16:26:55 -06:00
parent a6315a388f
commit 648bc3f49f
4 changed files with 39 additions and 21 deletions

View File

@ -832,6 +832,8 @@ LLVMIntrinsicIndex = enum
va_copy,
}
[extern] LLVMContextCreate = fn [cc(c)] () &LLVMContext;
ModuleLLVM = struct
{
context: &LLVMContext,
@ -2612,6 +2614,7 @@ parse = fn (module: &Module) void
emit = fn (module: &Module) void
{
>context = LLVMContextCreate();
}
compile = fn (arena: &Arena, options: CompileOptions) void

View File

@ -97,6 +97,7 @@ fn void compile(Arena* arena, Options options)
.library_directories = options.library_directories,
.library_names = options.library_names,
.library_paths = options.library_paths,
.link_libcpp = options.link_libcpp,
.target = options.target,
.build_mode = options.build_mode,
.has_debug_info = options.has_debug_info,
@ -250,6 +251,13 @@ fn String compile_file(Arena* arena, Compile options)
library_list = library_list(space + 1);
}
library_buffer[library_count] = string_literal("gcc");
library_count += 1;
library_buffer[library_count] = string_literal("gcc_s");
library_count += 1;
library_buffer[library_count] = string_literal("m");
library_count += 1;
library_names = { library_buffer, library_count };
}
else if (base_name.equal(string_literal("c_abi")))
@ -266,6 +274,7 @@ fn String compile_file(Arena* arena, Compile options)
.library_paths = library_paths,
.library_names = library_names,
.library_directories = library_directories,
.link_libcpp = is_compiler,
.target = {
.cpu = CPUArchitecture::x86_64,
.os = OperatingSystem::linux_,

View File

@ -1213,10 +1213,13 @@ struct Module
String name;
String path;
String executable;
Slice<String> objects;
Slice<String> library_directories;
Slice<String> library_names;
Slice<String> library_paths;
bool link_libc = true;
bool link_libcpp = false;
Target target;
BuildMode build_mode;
@ -1288,6 +1291,7 @@ struct Options
Slice<String> library_paths;
Slice<String> library_names;
Slice<String> library_directories;
bool link_libcpp;
Target target;
BuildMode build_mode;
bool has_debug_info;

View File

@ -8326,11 +8326,6 @@ fn void link(Module* module)
assert(module->executable.pointer[module->executable.length] == 0);
builder.add((char*)module->executable.pointer);
for (String object: module->objects)
{
builder.add(arena, object);
}
for (String library_directory: module->library_directories)
{
String parts[] = {
@ -8340,20 +8335,6 @@ fn void link(Module* module)
builder.add(arena, arena_join_string(arena, array_to_slice(parts)));
}
for (String library_path: module->library_paths)
{
builder.add(arena, library_path);
}
for (String library_name: module->library_names)
{
String parts[] = {
string_literal("-l"),
library_name,
};
builder.add(arena, arena_join_string(arena, array_to_slice(parts)));
}
String candidate_library_paths[] = {
string_literal("/usr/lib"),
string_literal("/usr/lib/x86_64-linux-gnu"),
@ -8391,8 +8372,29 @@ fn void link(Module* module)
builder.add((char*)arena_join_string(arena, array_to_slice(parts)).pointer);
}
auto link_libcpp = false;
if (link_libcpp)
builder.add("-L/usr/lib/gcc/x86_64-pc-linux-gnu/15.1.1");
builder.add("-L/usr/lib/gcc/x86_64-pc-linux-gnu/13");
for (String object: module->objects)
{
builder.add(arena, object);
}
for (String library_path: module->library_paths)
{
builder.add(arena, library_path);
}
for (String library_name: module->library_names)
{
String parts[] = {
string_literal("-l"),
library_name,
};
builder.add(arena, arena_join_string(arena, array_to_slice(parts)));
}
if (module->link_libcpp)
{
builder.add("-lstdc++");
}