Remove libc dependency for the generated code

This commit is contained in:
2024-05-23 01:13:16 +02:00
parent fb76cd1c77
commit 53dcbe56e1
14 changed files with 362 additions and 417 deletions

View File

@ -1,2 +0,0 @@
writei(3 + 4 + 5 + 1 + 2 + 4 + 3)
.

View File

@ -1 +0,0 @@
22

View File

@ -1 +1 @@
10
8

View File

@ -1 +1 @@
24
H

View File

@ -1,2 +1,2 @@
writei(5 * 2)
writei(4 * 2)
.

View File

@ -3,7 +3,6 @@
#include <filesystem>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <boost/process/env.hpp>
namespace elna
@ -105,22 +104,6 @@ namespace elna
return elna_child.wait();
}
std::string find_object(const std::vector<std::filesystem::path>& environment, const std::string& object)
{
auto variable = std::find(environment.cbegin(), environment.cend(), object);
for (const auto& variable : environment)
{
auto full_path = variable / object;
if (std::filesystem::exists(full_path))
{
return full_path.native();
}
}
return object;
}
test_status build_test(boost::asio::io_context& context, const std::filesystem::directory_entry& test_entry)
{
const std::filesystem::path test_filename = test_entry.path().filename();
@ -145,17 +128,7 @@ namespace elna
std::vector<std::filesystem::path> environment;
std::vector<std::string> linker_arguments = { "-o", test_binary.string() };
for (const auto segment : boost::this_process::environment()["LIBRARY_PATH"].to_vector())
{
linker_arguments.push_back("-L" + segment);
environment.push_back(std::filesystem::path(segment));
}
linker_arguments.push_back(find_object(environment, "crt0.o"));
linker_arguments.push_back(find_object(environment, "crtbegin.o"));
linker_arguments.push_back(test_object.string());
linker_arguments.insert(linker_arguments.cend(),
{ "--start-group", "-lgcc", "-lc", "-lgloss", "--end-group" });
linker_arguments.push_back(find_object(environment, "crtend.o"));
boost::process::v2::execute(boost::process::v2::process(context, boost::process::search_path("ld"),
linker_arguments
@ -248,7 +221,7 @@ namespace elna
"-nographic",
"-M", "virt",
"-bios", "default",
"-kernel", "build/tools/linux-5.15.158/arch/riscv/boot/Image",
"-kernel", "build/tools/linux-5.15.159/arch/riscv/boot/Image",
"-append", "quiet",
"-initrd", "build/root.cpio"
};