Switch to clang and improve cpprt
This commit is contained in:
@@ -31,7 +31,7 @@ Popcorn uses the `waf` build tool, which is included in the repo. The other
|
|||||||
requirements are:
|
requirements are:
|
||||||
|
|
||||||
* python (to run waf)
|
* python (to run waf)
|
||||||
* gcc
|
* clang
|
||||||
* nasm
|
* nasm
|
||||||
|
|
||||||
After cloning, run `waf configure`. Then you can run `waf build` to build the
|
After cloning, run `waf configure`. Then you can run `waf build` to build the
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ def configure(ctx):
|
|||||||
'EFI_DEBUG=0',
|
'EFI_DEBUG=0',
|
||||||
'EFI_DEBUG_CLEAR_MEMORY=0',
|
'EFI_DEBUG_CLEAR_MEMORY=0',
|
||||||
])
|
])
|
||||||
ctx.env.append_value('CFLAGS_EFI', ['-fPIC', '-fshort-wchar', '-Wa,--no-warn'])
|
ctx.env.append_value('CFLAGS_EFI', ['-fPIC', '-fshort-wchar'])
|
||||||
ctx.env.append_value('LINKFLAGS_EFI', [
|
ctx.env.append_value('LINKFLAGS_EFI', [
|
||||||
'-shared',
|
'-shared',
|
||||||
'-T', lds_path,
|
'-T', lds_path,
|
||||||
|
|||||||
@@ -1,3 +1,37 @@
|
|||||||
|
#include "kutil/assert.h"
|
||||||
|
|
||||||
|
using __exit_func = void (*)(void *);
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void __cxa_pure_virtual() { while(1); }
|
void *__dso_handle __attribute__ ((__weak__));
|
||||||
|
int __cxa_atexit(__exit_func, void *, void *);
|
||||||
|
void __cxa_pure_virtual();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct __exit_func_entry
|
||||||
|
{
|
||||||
|
__exit_func func;
|
||||||
|
void *obj;
|
||||||
|
void *dso;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int __num_exit_funcs = 0;
|
||||||
|
static const int __max_exit_funcs = 64;
|
||||||
|
__exit_func_entry __exit_funcs[__max_exit_funcs];
|
||||||
|
|
||||||
|
int
|
||||||
|
__cxa_atexit(__exit_func f, void *o, void *dso)
|
||||||
|
{
|
||||||
|
int i = __num_exit_funcs++;
|
||||||
|
if (i >= __max_exit_funcs) return -1;
|
||||||
|
__exit_funcs[i].func = f;
|
||||||
|
__exit_funcs[i].obj = o;
|
||||||
|
__exit_funcs[i].dso = dso;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void __cxa_pure_virtual()
|
||||||
|
{
|
||||||
|
kassert(0, "Pure virtual function call");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ kutil::memory_manager g_kernel_memory_manager;
|
|||||||
|
|
||||||
void * kalloc(size_t length) { return g_kernel_memory_manager.allocate(length); }
|
void * kalloc(size_t length) { return g_kernel_memory_manager.allocate(length); }
|
||||||
void kfree(void *p) { g_kernel_memory_manager.free(p); }
|
void kfree(void *p) { g_kernel_memory_manager.free(p); }
|
||||||
|
|
||||||
void * operator new (size_t n) { return g_kernel_memory_manager.allocate(n); }
|
void * operator new (size_t n) { return g_kernel_memory_manager.allocate(n); }
|
||||||
void * operator new[] (size_t n) { return g_kernel_memory_manager.allocate(n); }
|
void * operator new[] (size_t n) { return g_kernel_memory_manager.allocate(n); }
|
||||||
void operator delete (void *p) { return g_kernel_memory_manager.free(p); }
|
void operator delete (void *p) noexcept { return g_kernel_memory_manager.free(p); }
|
||||||
void operator delete[] (void *p){ return g_kernel_memory_manager.free(p); }
|
void operator delete[] (void *p) noexcept { return g_kernel_memory_manager.free(p); }
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ extern "C" {
|
|||||||
void *__bss_start, *__bss_end;
|
void *__bss_start, *__bss_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern [[noreturn]] void
|
extern void __kernel_assert(const char *, unsigned, const char *);
|
||||||
__kernel_assert(const char *file, unsigned line, const char *message);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
init_console(const popcorn_data *header)
|
init_console(const popcorn_data *header)
|
||||||
@@ -55,7 +54,7 @@ init_console(const popcorn_data *header)
|
|||||||
log::enable(logs::memory, log::level::debug);
|
log::enable(logs::memory, log::level::debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_error_3() { int x = 1 / 0; }
|
void do_error_3() { volatile int x = 1; volatile int y = 0; volatile int z = x / y; }
|
||||||
void do_error_2() { do_error_3(); }
|
void do_error_2() { do_error_3(); }
|
||||||
void do_error_1() { do_error_2(); }
|
void do_error_1() { do_error_2(); }
|
||||||
|
|
||||||
|
|||||||
@@ -357,7 +357,7 @@ find_efi_free_aligned_pages(const void *memory_map, size_t map_length, size_t de
|
|||||||
static unsigned
|
static unsigned
|
||||||
check_needs_page_ident(page_table *table, unsigned index, page_table **free_pages)
|
check_needs_page_ident(page_table *table, unsigned index, page_table **free_pages)
|
||||||
{
|
{
|
||||||
if (table->entries[index] & 0x1 == 1) return 0;
|
if ((table->entries[index] & 0x1) == 1) return 0;
|
||||||
|
|
||||||
kassert(*free_pages, "check_needs_page_ident needed to allocate but had no free pages");
|
kassert(*free_pages, "check_needs_page_ident needed to allocate but had no free pages");
|
||||||
|
|
||||||
@@ -404,6 +404,7 @@ page_in_ident(
|
|||||||
}
|
}
|
||||||
|
|
||||||
kassert(0, "Ran to end of page_in_ident");
|
kassert(0, "Ran to end of page_in_ident");
|
||||||
|
return 0; // Cannot reach
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -263,6 +263,7 @@ page_manager::get_block()
|
|||||||
return block;
|
return block;
|
||||||
} else {
|
} else {
|
||||||
kassert(0, "NYI: page_manager::get_block() needed to allocate.");
|
kassert(0, "NYI: page_manager::get_block() needed to allocate.");
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -431,7 +432,7 @@ page_manager::unmap_pages(addr_t address, size_t count)
|
|||||||
void
|
void
|
||||||
page_manager::check_needs_page(page_table *table, unsigned index)
|
page_manager::check_needs_page(page_table *table, unsigned index)
|
||||||
{
|
{
|
||||||
if (table->entries[index] & 0x1 == 1) return;
|
if ((table->entries[index] & 0x1) == 1) return;
|
||||||
|
|
||||||
page_table *new_table = get_table_page();
|
page_table *new_table = get_table_page();
|
||||||
for (int i=0; i<512; ++i) new_table->entries[i] = 0;
|
for (int i=0; i<512; ++i) new_table->entries[i] = 0;
|
||||||
@@ -527,7 +528,7 @@ page_table::dump(int level, uint64_t offset)
|
|||||||
uint64_t ent = entries[i];
|
uint64_t ent = entries[i];
|
||||||
if (ent == 0) continue;
|
if (ent == 0) continue;
|
||||||
|
|
||||||
if (ent & 0x1 == 0) {
|
if ((ent & 0x1) == 0) {
|
||||||
log::info(logs::memory, " %3d: %lx NOT PRESENT", i, ent);
|
log::info(logs::memory, " %3d: %lx NOT PRESENT", i, ent);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,4 +15,4 @@ extern assert_callback __kernel_assert_p;
|
|||||||
} // namespace kutil
|
} // namespace kutil
|
||||||
|
|
||||||
|
|
||||||
#define kassert(stmt, message) if(!(stmt)) { ::kutil::__kernel_assert_p(__FILE__, __LINE__, (message)); } else {}
|
#define kassert(stmt, message) do { if(!(stmt)) { ::kutil::__kernel_assert_p(__FILE__, __LINE__, (message)); }} while(0);
|
||||||
|
|||||||
6
wscript
6
wscript
@@ -9,7 +9,7 @@ class TestContext(BuildContext):
|
|||||||
|
|
||||||
|
|
||||||
def options(opt):
|
def options(opt):
|
||||||
opt.load("nasm gcc g++")
|
opt.load("nasm clang clang++")
|
||||||
|
|
||||||
opt.add_option(
|
opt.add_option(
|
||||||
'--arch',
|
'--arch',
|
||||||
@@ -36,7 +36,7 @@ def configure(ctx):
|
|||||||
ctx.find_program("ld", var="LINK_CC")
|
ctx.find_program("ld", var="LINK_CC")
|
||||||
ctx.env.LINK_CXX = ctx.env.LINK_CC
|
ctx.env.LINK_CXX = ctx.env.LINK_CC
|
||||||
|
|
||||||
ctx.load("nasm gcc g++")
|
ctx.load("nasm clang clang++")
|
||||||
ctx.find_program("objcopy", var="objcopy")
|
ctx.find_program("objcopy", var="objcopy")
|
||||||
ctx.find_program("objdump", var="objdump")
|
ctx.find_program("objdump", var="objdump")
|
||||||
ctx.find_program("mcopy", var="mcopy")
|
ctx.find_program("mcopy", var="mcopy")
|
||||||
@@ -158,7 +158,7 @@ def configure(ctx):
|
|||||||
##
|
##
|
||||||
from waflib.ConfigSet import ConfigSet
|
from waflib.ConfigSet import ConfigSet
|
||||||
ctx.setenv('tests', env=ConfigSet())
|
ctx.setenv('tests', env=ConfigSet())
|
||||||
ctx.load("g++")
|
ctx.load("clang++")
|
||||||
|
|
||||||
ctx.env.append_value('INCLUDES', [
|
ctx.env.append_value('INCLUDES', [
|
||||||
join(ctx.path.abspath(), "src", "include"),
|
join(ctx.path.abspath(), "src", "include"),
|
||||||
|
|||||||
Reference in New Issue
Block a user