aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2021-03-15 21:07:59 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2021-03-15 21:07:59 +0200
commit8b88f3f7fd143fc542a5118d50a7a981464270d5 (patch)
tree86b4ca2b14b3594d3eaa7ff449db72920cad2b70
parentEnable ThinLTO (diff)
downloadkernel.cpp-8b88f3f7fd143fc542a5118d50a7a981464270d5.tar.xz
Fix compile failure without -O2
Linking fails without lto on
-rw-r--r--makefile2
-rw-r--r--src/gdt.cc18
-rw-r--r--src/gdt.h6
-rw-r--r--src/memory.cc5
-rw-r--r--toolchain.makefile7
5 files changed, 21 insertions, 17 deletions
diff --git a/makefile b/makefile
index 5ebde01..5f2d833 100644
--- a/makefile
+++ b/makefile
@@ -18,7 +18,6 @@ CXX_SYSTEM_INCLUDE := $(addprefix -isystem, $(CXX_SYSTEM_INCLUDE))
$(OBJ_DIR)/glitch.elf: $(autogen) $(AS_OBJ) $(CXX_OBJ) linker.ld
@echo " LD $@"
- @mkdir -p $(OBJ_DIR)/thinlto_cache
@$(LD) $(LD_FLAGS) -o $@ $(AS_OBJ) $(CXX_OBJ)
$(AS_OBJ): $(OBJ_DIR)/%.o: %.S
@@ -39,6 +38,7 @@ $(CXX_TEST_OBJ): $(OBJ_DIR)/%.o : %.cc
clean:
@rm -rf $(autogen) $(AS_OBJ) $(CXX_OBJ) $(CXX_DEP) $(CXX_TEST_OBJ) $(OBJ_DIR)/glitch.elf $(OBJ_DIR)/isodir
+ @rm -rf $(OBJ_DIR)/*_cache
@make -C tools/kconfig OBJ_DIR=$(CURDIR)/$(OBJ_DIR)/kconfig clean
# testing
diff --git a/src/gdt.cc b/src/gdt.cc
index 7b5e3df..726a7d7 100644
--- a/src/gdt.cc
+++ b/src/gdt.cc
@@ -14,9 +14,9 @@ constexpr uint32_t kseg_start = 0;
constexpr uint32_t kseg_sz = 0xffffffff;
__attribute__((section(".constinit"))) static GDT::SegmentDescriptor segments[256]{
- [GDT::null0] = seg::make<null_sz>(0, {}),
- [GDT::kcode] = seg::make<kseg_sz>(kseg_start, {.r_w = true, .exe = true, .segment = true, .present = true}),
- [GDT::kdata] = seg::make<kseg_sz>(kseg_start, {.r_w = true, .segment = true, .present = true}),
+ seg::make<null_sz>(0, {}),
+ seg::make<kseg_sz>(kseg_start, {.r_w = true, .exe = true, .segment = true, .present = true}),
+ seg::make<kseg_sz>(kseg_start, {.r_w = true, .segment = true, .present = true}),
};
GDT::GDT() {
@@ -24,23 +24,19 @@ GDT::GDT() {
asm volatile("lgdt %0" : : "p"(gdtr));
// flush the segment registers
- const auto cs = descriptor(kcode);
- const auto ds = descriptor(kdata);
+ constexpr auto cs = GDT::descriptor(kcode);
+ constexpr auto ds = GDT::descriptor(kdata);
asm volatile(
- "jmp %0,$.reload_cs\n\t" // far jump takes cs
+ "jmpl %0,$.reload_cs\n\t" // far jump: cs,location
".reload_cs:\n\t"
" mov %1, %%ds\n\t" // ds
" mov %1, %%es\n\t"
" mov %1, %%fs\n\t"
" mov %1, %%gs\n\t"
" mov %1, %%ss\n\t" ::"i"(cs),
- "r"(ds));
+ "rm"(ds));
printk("GDT installed at ", uhex{gdtr.base}, '\n');
}
-uint16_t GDT::descriptor(GDT::SegmentMap i) const {
- return static_cast<uint16_t>(reinterpret_cast<const uint32_t>(&segments[i]) -
- reinterpret_cast<const uint32_t>(&segments));
-}
diff --git a/src/gdt.h b/src/gdt.h
index 6aeaa33..4deeec3 100644
--- a/src/gdt.h
+++ b/src/gdt.h
@@ -95,11 +95,13 @@ public:
unsigned int base_31_24 : 8 = 0; // high bits of segment address
} __attribute__((packed));
- enum SegmentMap { null0, kcode, kdata };
+ enum SegmentMap { null0 = 0, kcode = 1, kdata = 2 };
GDT();
~GDT() = default;
- uint16_t descriptor(SegmentMap) const;
+ static constexpr uint16_t descriptor(GDT::SegmentMap i) {
+ return static_cast<uint16_t>(i * sizeof(SegmentDescriptor));
+ }
};
diff --git a/src/memory.cc b/src/memory.cc
index a2a2561..2d440a3 100644
--- a/src/memory.cc
+++ b/src/memory.cc
@@ -4,3 +4,8 @@ void operator delete(void*) {
printk("Calling delete\n");
abort();
}
+
+extern "C" void __cxa_pure_virtual() {
+ printk("__cxa_pure_virtual\n");
+ abort();
+}
diff --git a/toolchain.makefile b/toolchain.makefile
index d8f09f7..ce8fdc6 100644
--- a/toolchain.makefile
+++ b/toolchain.makefile
@@ -8,13 +8,14 @@ AS := clang
AS_FLAGS :=
LD := ld.lld
-LD_FLAGS := -T linker.ld --thinlto-cache-dir=$(OBJ_DIR)/thinlto_cache
+LD_FLAGS := -nostdlib -T linker.ld --thinlto-cache-dir=$(OBJ_DIR)/thinlto_cache
+# TODO: linking fails with -O0 and -O1 without -flto=thin
CXX := clang++
TEST_CXX := clang++
-CXX_FLAGS := -std=c++20 -g \
+CXX_FLAGS := -std=c++20 -g -O2 -flto=thin \
-mkernel -ffreestanding -nostdlib -nostdinc -nostdinc++ \
- -Wall -Wextra -Werror=pedantic -O2 -flto=thin \
+ -Wall -Wextra -Werror=pedantic \
-Werror=date-time \
-Werror=shadow-all \
-Wold-style-cast -Wconversion \