1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 17:27:35 +00:00

Kernel: Enable building the kernel with -flto

GCC with -flto is more aggressive when it comes to inlining and
discarding functions which is why we must mark some of the functions
as NEVER_INLINE (because they contain asm labels which would be
duplicated in the object files if the compiler decides to inline
the function elsewhere) and __attribute__((used)) for others so
that GCC doesn't discard them.
This commit is contained in:
Gunnar Beutner 2021-04-29 14:54:15 +02:00 committed by Andreas Kling
parent b861259098
commit 55ae52fdf8
9 changed files with 57 additions and 57 deletions

View file

@ -47,20 +47,20 @@ static EntropySource s_entropy_source_interrupts { EntropySource::Static::Interr
// The compiler can't see the calls to these functions inside assembly. // The compiler can't see the calls to these functions inside assembly.
// Declare them, to avoid dead code warnings. // Declare them, to avoid dead code warnings.
extern "C" void enter_thread_context(Thread* from_thread, Thread* to_thread); extern "C" void enter_thread_context(Thread* from_thread, Thread* to_thread) __attribute__((used));
extern "C" void context_first_init(Thread* from_thread, Thread* to_thread, TrapFrame* trap); extern "C" void context_first_init(Thread* from_thread, Thread* to_thread, TrapFrame* trap) __attribute__((used));
extern "C" u32 do_init_context(Thread* thread, u32 flags); extern "C" u32 do_init_context(Thread* thread, u32 flags) __attribute__((used));
extern "C" void exit_kernel_thread(void); extern "C" void exit_kernel_thread(void);
extern "C" void pre_init_finished(void); extern "C" void pre_init_finished(void) __attribute__((used));
extern "C" void post_init_finished(void); extern "C" void post_init_finished(void) __attribute__((used));
extern "C" void handle_interrupt(TrapFrame*); extern "C" void handle_interrupt(TrapFrame*) __attribute__((used));
// clang-format off // clang-format off
#if ARCH(I386) #if ARCH(I386)
#define EH_ENTRY(ec, title) \ #define EH_ENTRY(ec, title) \
extern "C" void title##_asm_entry(); \ extern "C" void title##_asm_entry(); \
extern "C" void title##_handler(TrapFrame*); \ extern "C" void title##_handler(TrapFrame*) __attribute__((used)); \
asm( \ asm( \
".globl " #title "_asm_entry\n" \ ".globl " #title "_asm_entry\n" \
"" #title "_asm_entry: \n" \ "" #title "_asm_entry: \n" \
@ -84,8 +84,8 @@ extern "C" void handle_interrupt(TrapFrame*);
" jmp common_trap_exit \n"); " jmp common_trap_exit \n");
#define EH_ENTRY_NO_CODE(ec, title) \ #define EH_ENTRY_NO_CODE(ec, title) \
extern "C" void title##_handler(TrapFrame*); \ extern "C" void title##_asm_entry(); \
extern "C" void title##_asm_entry(); \ extern "C" void title##_handler(TrapFrame*) __attribute__((used)); \
asm( \ asm( \
".globl " #title "_asm_entry\n" \ ".globl " #title "_asm_entry\n" \
"" #title "_asm_entry: \n" \ "" #title "_asm_entry: \n" \

View file

@ -40,7 +40,7 @@ extern "C" u8* safe_atomic_compare_exchange_relaxed_faulted;
namespace Kernel { namespace Kernel {
CODE_SECTION(".text.safemem") CODE_SECTION(".text.safemem")
bool safe_memcpy(void* dest_ptr, const void* src_ptr, size_t n, void*& fault_at) NEVER_INLINE bool safe_memcpy(void* dest_ptr, const void* src_ptr, size_t n, void*& fault_at)
{ {
fault_at = nullptr; fault_at = nullptr;
size_t dest = (size_t)dest_ptr; size_t dest = (size_t)dest_ptr;
@ -86,7 +86,7 @@ bool safe_memcpy(void* dest_ptr, const void* src_ptr, size_t n, void*& fault_at)
} }
CODE_SECTION(".text.safemem") CODE_SECTION(".text.safemem")
ssize_t safe_strnlen(const char* str, size_t max_n, void*& fault_at) NEVER_INLINE ssize_t safe_strnlen(const char* str, size_t max_n, void*& fault_at)
{ {
ssize_t count = 0; ssize_t count = 0;
fault_at = nullptr; fault_at = nullptr;
@ -115,7 +115,7 @@ ssize_t safe_strnlen(const char* str, size_t max_n, void*& fault_at)
} }
CODE_SECTION(".text.safemem") CODE_SECTION(".text.safemem")
bool safe_memset(void* dest_ptr, int c, size_t n, void*& fault_at) NEVER_INLINE bool safe_memset(void* dest_ptr, int c, size_t n, void*& fault_at)
{ {
fault_at = nullptr; fault_at = nullptr;
size_t dest = (size_t)dest_ptr; size_t dest = (size_t)dest_ptr;
@ -163,7 +163,7 @@ bool safe_memset(void* dest_ptr, int c, size_t n, void*& fault_at)
} }
CODE_SECTION(".text.safemem.atomic") CODE_SECTION(".text.safemem.atomic")
Optional<u32> safe_atomic_fetch_add_relaxed(volatile u32* var, u32 val) NEVER_INLINE Optional<u32> safe_atomic_fetch_add_relaxed(volatile u32* var, u32 val)
{ {
u32 result; u32 result;
bool error; bool error;
@ -181,7 +181,7 @@ Optional<u32> safe_atomic_fetch_add_relaxed(volatile u32* var, u32 val)
} }
CODE_SECTION(".text.safemem.atomic") CODE_SECTION(".text.safemem.atomic")
Optional<u32> safe_atomic_exchange_relaxed(volatile u32* var, u32 val) NEVER_INLINE Optional<u32> safe_atomic_exchange_relaxed(volatile u32* var, u32 val)
{ {
u32 result; u32 result;
bool error; bool error;
@ -199,7 +199,7 @@ Optional<u32> safe_atomic_exchange_relaxed(volatile u32* var, u32 val)
} }
CODE_SECTION(".text.safemem.atomic") CODE_SECTION(".text.safemem.atomic")
Optional<u32> safe_atomic_load_relaxed(volatile u32* var) NEVER_INLINE Optional<u32> safe_atomic_load_relaxed(volatile u32* var)
{ {
u32 result; u32 result;
bool error; bool error;
@ -217,7 +217,7 @@ Optional<u32> safe_atomic_load_relaxed(volatile u32* var)
} }
CODE_SECTION(".text.safemem.atomic") CODE_SECTION(".text.safemem.atomic")
bool safe_atomic_store_relaxed(volatile u32* var, u32 val) NEVER_INLINE bool safe_atomic_store_relaxed(volatile u32* var, u32 val)
{ {
bool error; bool error;
asm volatile( asm volatile(
@ -232,7 +232,7 @@ bool safe_atomic_store_relaxed(volatile u32* var, u32 val)
} }
CODE_SECTION(".text.safemem.atomic") CODE_SECTION(".text.safemem.atomic")
Optional<bool> safe_atomic_compare_exchange_relaxed(volatile u32* var, u32& expected, u32 val) NEVER_INLINE Optional<bool> safe_atomic_compare_exchange_relaxed(volatile u32* var, u32& expected, u32 val)
{ {
// NOTE: accessing expected is NOT protected as it should always point // NOTE: accessing expected is NOT protected as it should always point
// to a valid location in kernel memory! // to a valid location in kernel memory!

View file

@ -980,7 +980,7 @@ public:
void exit_trap(TrapFrame& trap); void exit_trap(TrapFrame& trap);
[[noreturn]] void initialize_context_switching(Thread& initial_thread); [[noreturn]] void initialize_context_switching(Thread& initial_thread);
void switch_context(Thread*& from_thread, Thread*& to_thread); NEVER_INLINE void switch_context(Thread*& from_thread, Thread*& to_thread);
[[noreturn]] static void assume_context(Thread& thread, FlatPtr flags); [[noreturn]] static void assume_context(Thread& thread, FlatPtr flags);
u32 init_context(Thread& thread, bool leave_crit); u32 init_context(Thread& thread, bool leave_crit);
static Vector<FlatPtr> capture_stack_trace(Thread& thread, size_t max_frames = 0); static Vector<FlatPtr> capture_stack_trace(Thread& thread, size_t max_frames = 0);
@ -1057,9 +1057,9 @@ struct TrapFrame {
static_assert(TRAP_FRAME_SIZE == sizeof(TrapFrame)); static_assert(TRAP_FRAME_SIZE == sizeof(TrapFrame));
extern "C" void enter_trap_no_irq(TrapFrame*); extern "C" void enter_trap_no_irq(TrapFrame*) __attribute__((used));
extern "C" void enter_trap(TrapFrame*); extern "C" void enter_trap(TrapFrame*) __attribute__((used));
extern "C" void exit_trap(TrapFrame*); extern "C" void exit_trap(TrapFrame*) __attribute__((used));
class MSR { class MSR {
uint32_t m_msr; uint32_t m_msr;

View file

@ -14,14 +14,14 @@ namespace Kernel {
struct RegisterState; struct RegisterState;
[[nodiscard]] bool safe_memcpy(void* dest_ptr, const void* src_ptr, size_t n, void*& fault_at); [[nodiscard]] bool safe_memcpy(void* dest_ptr, const void* src_ptr, size_t n, void*& fault_at) __attribute__((used));
[[nodiscard]] ssize_t safe_strnlen(const char* str, size_t max_n, void*& fault_at); [[nodiscard]] ssize_t safe_strnlen(const char* str, size_t max_n, void*& fault_at) __attribute__((used));
[[nodiscard]] bool safe_memset(void* dest_ptr, int c, size_t n, void*& fault_at); [[nodiscard]] bool safe_memset(void* dest_ptr, int c, size_t n, void*& fault_at) __attribute__((used));
[[nodiscard]] Optional<u32> safe_atomic_fetch_add_relaxed(volatile u32* var, u32 val); [[nodiscard]] Optional<u32> safe_atomic_fetch_add_relaxed(volatile u32* var, u32 val) __attribute__((used));
[[nodiscard]] Optional<u32> safe_atomic_exchange_relaxed(volatile u32* var, u32 val); [[nodiscard]] Optional<u32> safe_atomic_exchange_relaxed(volatile u32* var, u32 val) __attribute__((used));
[[nodiscard]] Optional<u32> safe_atomic_load_relaxed(volatile u32* var); [[nodiscard]] Optional<u32> safe_atomic_load_relaxed(volatile u32* var) __attribute__((used));
[[nodiscard]] bool safe_atomic_store_relaxed(volatile u32* var, u32 val); [[nodiscard]] bool safe_atomic_store_relaxed(volatile u32* var, u32 val) __attribute__((used));
[[nodiscard]] Optional<bool> safe_atomic_compare_exchange_relaxed(volatile u32* var, u32& expected, u32 val); [[nodiscard]] Optional<bool> safe_atomic_compare_exchange_relaxed(volatile u32* var, u32& expected, u32 val) __attribute__((used));
[[nodiscard]] ALWAYS_INLINE Optional<u32> safe_atomic_fetch_and_relaxed(volatile u32* var, u32 val) [[nodiscard]] ALWAYS_INLINE Optional<u32> safe_atomic_fetch_and_relaxed(volatile u32* var, u32 val)
{ {

View file

@ -256,7 +256,7 @@ Process::~Process()
} }
// Make sure the compiler doesn't "optimize away" this function: // Make sure the compiler doesn't "optimize away" this function:
extern void signal_trampoline_dummy(); extern void signal_trampoline_dummy() __attribute__((used));
void signal_trampoline_dummy() void signal_trampoline_dummy()
{ {
#if ARCH(I386) #if ARCH(I386)
@ -287,7 +287,7 @@ void signal_trampoline_dummy()
#endif #endif
} }
extern "C" void asm_signal_trampoline(void); extern "C" void asm_signal_trampoline(void) __attribute__((used));
extern "C" void asm_signal_trampoline_end(void); extern "C" void asm_signal_trampoline_end(void);
void create_signal_trampoline() void create_signal_trampoline()

View file

@ -359,8 +359,8 @@ void free(void* p)
// Functions that are automatically called by the C++ compiler. // Functions that are automatically called by the C++ compiler.
// Declare them first, to tell the silly compiler that they are indeed being used. // Declare them first, to tell the silly compiler that they are indeed being used.
[[noreturn]] void __stack_chk_fail(); [[noreturn]] void __stack_chk_fail() __attribute__((used));
[[noreturn]] void __stack_chk_fail_local(); [[noreturn]] void __stack_chk_fail_local() __attribute__((used));
extern "C" int __cxa_atexit(void (*)(void*), void*, void*); extern "C" int __cxa_atexit(void (*)(void*), void*, void*);
[[noreturn]] void __cxa_pure_virtual(); [[noreturn]] void __cxa_pure_virtual();

View file

@ -13,7 +13,7 @@
namespace Kernel { namespace Kernel {
extern "C" void syscall_handler(TrapFrame*); extern "C" void syscall_handler(TrapFrame*) __attribute__((used));
extern "C" void syscall_asm_entry(); extern "C" void syscall_asm_entry();
// clang-format off // clang-format off
@ -129,7 +129,7 @@ KResultOr<FlatPtr> handle(RegisterState& regs, FlatPtr function, FlatPtr arg1, F
} }
void syscall_handler(TrapFrame* trap) NEVER_INLINE void syscall_handler(TrapFrame* trap)
{ {
auto& regs = *trap->regs; auto& regs = *trap->regs;
auto current_thread = Thread::current(); auto current_thread = Thread::current();

View file

@ -28,49 +28,49 @@ static void print_location(const SourceLocation& location)
PANIC("UB is configured to be deadly."); PANIC("UB is configured to be deadly.");
} }
void __ubsan_handle_load_invalid_value(const InvalidValueData&, ValueHandle); void __ubsan_handle_load_invalid_value(const InvalidValueData&, ValueHandle) __attribute__((used));
void __ubsan_handle_load_invalid_value(const InvalidValueData& data, ValueHandle) void __ubsan_handle_load_invalid_value(const InvalidValueData& data, ValueHandle)
{ {
dbgln("KUBSAN: load-invalid-value: {} ({}-bit)", data.type.name(), data.type.bit_width()); dbgln("KUBSAN: load-invalid-value: {} ({}-bit)", data.type.name(), data.type.bit_width());
print_location(data.location); print_location(data.location);
} }
void __ubsan_handle_nonnull_arg(const NonnullArgData&); void __ubsan_handle_nonnull_arg(const NonnullArgData&) __attribute__((used));
void __ubsan_handle_nonnull_arg(const NonnullArgData& data) void __ubsan_handle_nonnull_arg(const NonnullArgData& data)
{ {
dbgln("KUBSAN: null pointer passed as argument {}, which is declared to never be null", data.argument_index); dbgln("KUBSAN: null pointer passed as argument {}, which is declared to never be null", data.argument_index);
print_location(data.location); print_location(data.location);
} }
void __ubsan_handle_nullability_arg(const NonnullArgData&); void __ubsan_handle_nullability_arg(const NonnullArgData&) __attribute__((used));
void __ubsan_handle_nullability_arg(const NonnullArgData& data) void __ubsan_handle_nullability_arg(const NonnullArgData& data)
{ {
dbgln("KUBSAN: null pointer passed as argument {}, which is declared to never be null", data.argument_index); dbgln("KUBSAN: null pointer passed as argument {}, which is declared to never be null", data.argument_index);
print_location(data.location); print_location(data.location);
} }
void __ubsan_handle_nonnull_return_v1(const NonnullReturnData&, const SourceLocation&); void __ubsan_handle_nonnull_return_v1(const NonnullReturnData&, const SourceLocation&) __attribute__((used));
void __ubsan_handle_nonnull_return_v1(const NonnullReturnData&, const SourceLocation& location) void __ubsan_handle_nonnull_return_v1(const NonnullReturnData&, const SourceLocation& location)
{ {
dbgln("KUBSAN: null pointer return from function declared to never return null"); dbgln("KUBSAN: null pointer return from function declared to never return null");
print_location(location); print_location(location);
} }
void __ubsan_handle_nullability_return_v1(const NonnullReturnData& data, const SourceLocation& location); void __ubsan_handle_nullability_return_v1(const NonnullReturnData& data, const SourceLocation& location) __attribute__((used));
void __ubsan_handle_nullability_return_v1(const NonnullReturnData&, const SourceLocation& location) void __ubsan_handle_nullability_return_v1(const NonnullReturnData&, const SourceLocation& location)
{ {
dbgln("KUBSAN: null pointer return from function declared to never return null"); dbgln("KUBSAN: null pointer return from function declared to never return null");
print_location(location); print_location(location);
} }
void __ubsan_handle_vla_bound_not_positive(const VLABoundData&, ValueHandle); void __ubsan_handle_vla_bound_not_positive(const VLABoundData&, ValueHandle) __attribute__((used));
void __ubsan_handle_vla_bound_not_positive(const VLABoundData& data, ValueHandle) void __ubsan_handle_vla_bound_not_positive(const VLABoundData& data, ValueHandle)
{ {
dbgln("KUBSAN: VLA bound not positive {} ({}-bit)", data.type.name(), data.type.bit_width()); dbgln("KUBSAN: VLA bound not positive {} ({}-bit)", data.type.name(), data.type.bit_width());
print_location(data.location); print_location(data.location);
} }
void __ubsan_handle_add_overflow(const OverflowData&, ValueHandle lhs, ValueHandle rhs); void __ubsan_handle_add_overflow(const OverflowData&, ValueHandle lhs, ValueHandle rhs) __attribute__((used));
void __ubsan_handle_add_overflow(const OverflowData& data, ValueHandle, ValueHandle) void __ubsan_handle_add_overflow(const OverflowData& data, ValueHandle, ValueHandle)
{ {
dbgln("KUBSAN: addition overflow, {} ({}-bit)", data.type.name(), data.type.bit_width()); dbgln("KUBSAN: addition overflow, {} ({}-bit)", data.type.name(), data.type.bit_width());
@ -78,7 +78,7 @@ void __ubsan_handle_add_overflow(const OverflowData& data, ValueHandle, ValueHan
print_location(data.location); print_location(data.location);
} }
void __ubsan_handle_sub_overflow(const OverflowData&, ValueHandle lhs, ValueHandle rhs); void __ubsan_handle_sub_overflow(const OverflowData&, ValueHandle lhs, ValueHandle rhs) __attribute__((used));
void __ubsan_handle_sub_overflow(const OverflowData& data, ValueHandle, ValueHandle) void __ubsan_handle_sub_overflow(const OverflowData& data, ValueHandle, ValueHandle)
{ {
dbgln("KUBSAN: subtraction overflow, {} ({}-bit)", data.type.name(), data.type.bit_width()); dbgln("KUBSAN: subtraction overflow, {} ({}-bit)", data.type.name(), data.type.bit_width());
@ -86,7 +86,7 @@ void __ubsan_handle_sub_overflow(const OverflowData& data, ValueHandle, ValueHan
print_location(data.location); print_location(data.location);
} }
void __ubsan_handle_negate_overflow(const OverflowData&, ValueHandle); void __ubsan_handle_negate_overflow(const OverflowData&, ValueHandle) __attribute__((used));
void __ubsan_handle_negate_overflow(const OverflowData& data, ValueHandle) void __ubsan_handle_negate_overflow(const OverflowData& data, ValueHandle)
{ {
dbgln("KUBSAN: negation overflow, {} ({}-bit)", data.type.name(), data.type.bit_width()); dbgln("KUBSAN: negation overflow, {} ({}-bit)", data.type.name(), data.type.bit_width());
@ -94,35 +94,35 @@ void __ubsan_handle_negate_overflow(const OverflowData& data, ValueHandle)
print_location(data.location); print_location(data.location);
} }
void __ubsan_handle_mul_overflow(const OverflowData&, ValueHandle lhs, ValueHandle rhs); void __ubsan_handle_mul_overflow(const OverflowData&, ValueHandle lhs, ValueHandle rhs) __attribute__((used));
void __ubsan_handle_mul_overflow(const OverflowData& data, ValueHandle, ValueHandle) void __ubsan_handle_mul_overflow(const OverflowData& data, ValueHandle, ValueHandle)
{ {
dbgln("KUBSAN: multiplication overflow, {} ({}-bit)", data.type.name(), data.type.bit_width()); dbgln("KUBSAN: multiplication overflow, {} ({}-bit)", data.type.name(), data.type.bit_width());
print_location(data.location); print_location(data.location);
} }
void __ubsan_handle_shift_out_of_bounds(const ShiftOutOfBoundsData&, ValueHandle lhs, ValueHandle rhs); void __ubsan_handle_shift_out_of_bounds(const ShiftOutOfBoundsData&, ValueHandle lhs, ValueHandle rhs) __attribute__((used));
void __ubsan_handle_shift_out_of_bounds(const ShiftOutOfBoundsData& data, ValueHandle, ValueHandle) void __ubsan_handle_shift_out_of_bounds(const ShiftOutOfBoundsData& data, ValueHandle, ValueHandle)
{ {
dbgln("KUBSAN: shift out of bounds, {} ({}-bit) shifted by {} ({}-bit)", data.lhs_type.name(), data.lhs_type.bit_width(), data.rhs_type.name(), data.rhs_type.bit_width()); dbgln("KUBSAN: shift out of bounds, {} ({}-bit) shifted by {} ({}-bit)", data.lhs_type.name(), data.lhs_type.bit_width(), data.rhs_type.name(), data.rhs_type.bit_width());
print_location(data.location); print_location(data.location);
} }
void __ubsan_handle_divrem_overflow(const OverflowData&, ValueHandle lhs, ValueHandle rhs); void __ubsan_handle_divrem_overflow(const OverflowData&, ValueHandle lhs, ValueHandle rhs) __attribute__((used));
void __ubsan_handle_divrem_overflow(const OverflowData& data, ValueHandle, ValueHandle) void __ubsan_handle_divrem_overflow(const OverflowData& data, ValueHandle, ValueHandle)
{ {
dbgln("KUBSAN: divrem overflow, {} ({}-bit)", data.type.name(), data.type.bit_width()); dbgln("KUBSAN: divrem overflow, {} ({}-bit)", data.type.name(), data.type.bit_width());
print_location(data.location); print_location(data.location);
} }
void __ubsan_handle_out_of_bounds(const OutOfBoundsData&, ValueHandle); void __ubsan_handle_out_of_bounds(const OutOfBoundsData&, ValueHandle) __attribute__((used));
void __ubsan_handle_out_of_bounds(const OutOfBoundsData& data, ValueHandle) void __ubsan_handle_out_of_bounds(const OutOfBoundsData& data, ValueHandle)
{ {
dbgln("KUBSAN: out of bounds access into array of {} ({}-bit), index type {} ({}-bit)", data.array_type.name(), data.array_type.bit_width(), data.index_type.name(), data.index_type.bit_width()); dbgln("KUBSAN: out of bounds access into array of {} ({}-bit), index type {} ({}-bit)", data.array_type.name(), data.array_type.bit_width(), data.index_type.name(), data.index_type.bit_width());
print_location(data.location); print_location(data.location);
} }
void __ubsan_handle_type_mismatch_v1(const TypeMismatchData&, ValueHandle); void __ubsan_handle_type_mismatch_v1(const TypeMismatchData&, ValueHandle) __attribute__((used));
void __ubsan_handle_type_mismatch_v1(const TypeMismatchData& data, ValueHandle ptr) void __ubsan_handle_type_mismatch_v1(const TypeMismatchData& data, ValueHandle ptr)
{ {
static const char* kinds[] = { static const char* kinds[] = {
@ -155,7 +155,7 @@ void __ubsan_handle_type_mismatch_v1(const TypeMismatchData& data, ValueHandle p
} }
// FIXME: Causes a triple fault on boot // FIXME: Causes a triple fault on boot
void __ubsan_handle_alignment_assumption(const AlignmentAssumptionData&, ValueHandle, ValueHandle, ValueHandle); void __ubsan_handle_alignment_assumption(const AlignmentAssumptionData&, ValueHandle, ValueHandle, ValueHandle) __attribute__((used));
void __ubsan_handle_alignment_assumption(const AlignmentAssumptionData& data, ValueHandle pointer, ValueHandle alignment, ValueHandle offset) void __ubsan_handle_alignment_assumption(const AlignmentAssumptionData& data, ValueHandle pointer, ValueHandle alignment, ValueHandle offset)
{ {
if (offset) { if (offset) {
@ -172,21 +172,21 @@ void __ubsan_handle_alignment_assumption(const AlignmentAssumptionData& data, Va
print_location(data.location); print_location(data.location);
} }
void __ubsan_handle_builtin_unreachable(const UnreachableData&); void __ubsan_handle_builtin_unreachable(const UnreachableData&) __attribute__((used));
void __ubsan_handle_builtin_unreachable(const UnreachableData& data) void __ubsan_handle_builtin_unreachable(const UnreachableData& data)
{ {
dbgln("KUBSAN: execution reached an unreachable program point"); dbgln("KUBSAN: execution reached an unreachable program point");
print_location(data.location); print_location(data.location);
} }
void __ubsan_handle_missing_return(const UnreachableData&); void __ubsan_handle_missing_return(const UnreachableData&) __attribute__((used));
void __ubsan_handle_missing_return(const UnreachableData& data) void __ubsan_handle_missing_return(const UnreachableData& data)
{ {
dbgln("KUBSAN: execution reached the end of a value-returning function without returning a value"); dbgln("KUBSAN: execution reached the end of a value-returning function without returning a value");
print_location(data.location); print_location(data.location);
} }
void __ubsan_handle_implicit_conversion(const ImplicitConversionData&, ValueHandle, ValueHandle); void __ubsan_handle_implicit_conversion(const ImplicitConversionData&, ValueHandle, ValueHandle) __attribute__((used));
void __ubsan_handle_implicit_conversion(const ImplicitConversionData& data, ValueHandle, ValueHandle) void __ubsan_handle_implicit_conversion(const ImplicitConversionData& data, ValueHandle, ValueHandle)
{ {
const char* src_signed = data.from_type.is_signed() ? "" : "un"; const char* src_signed = data.from_type.is_signed() ? "" : "un";
@ -196,7 +196,7 @@ void __ubsan_handle_implicit_conversion(const ImplicitConversionData& data, Valu
print_location(data.location); print_location(data.location);
} }
void __ubsan_handle_invalid_builtin(const InvalidBuiltinData); void __ubsan_handle_invalid_builtin(const InvalidBuiltinData) __attribute__((used));
void __ubsan_handle_invalid_builtin(const InvalidBuiltinData data) void __ubsan_handle_invalid_builtin(const InvalidBuiltinData data)
{ {
dbgln("KUBSAN: passing invalid argument"); dbgln("KUBSAN: passing invalid argument");
@ -204,7 +204,7 @@ void __ubsan_handle_invalid_builtin(const InvalidBuiltinData data)
} }
// FIXME: Causes a triple fault on boot // FIXME: Causes a triple fault on boot
void __ubsan_handle_pointer_overflow(const PointerOverflowData&, ValueHandle, ValueHandle); void __ubsan_handle_pointer_overflow(const PointerOverflowData&, ValueHandle, ValueHandle) __attribute__((used));
void __ubsan_handle_pointer_overflow(const PointerOverflowData& data, ValueHandle base, ValueHandle result) void __ubsan_handle_pointer_overflow(const PointerOverflowData& data, ValueHandle base, ValueHandle result)
{ {
if (base == 0 && result == 0) { if (base == 0 && result == 0) {

View file

@ -71,7 +71,7 @@ extern "C" u8* end_of_safemem_text;
extern "C" u8* start_of_safemem_atomic_text; extern "C" u8* start_of_safemem_atomic_text;
extern "C" u8* end_of_safemem_atomic_text; extern "C" u8* end_of_safemem_atomic_text;
extern "C" FlatPtr end_of_kernel_image; extern "C" u8* end_of_kernel_image;
multiboot_module_entry_t multiboot_copy_boot_modules_array[16]; multiboot_module_entry_t multiboot_copy_boot_modules_array[16];
size_t multiboot_copy_boot_modules_count; size_t multiboot_copy_boot_modules_count;
@ -85,7 +85,7 @@ static void setup_serial_debug();
// boot.S expects these functions to exactly have the following signatures. // boot.S expects these functions to exactly have the following signatures.
// We declare them here to ensure their signatures don't accidentally change. // We declare them here to ensure their signatures don't accidentally change.
extern "C" void init_finished(u32 cpu); extern "C" void init_finished(u32 cpu) __attribute__((used));
extern "C" [[noreturn]] void init_ap(u32 cpu, Processor* processor_info); extern "C" [[noreturn]] void init_ap(u32 cpu, Processor* processor_info);
extern "C" [[noreturn]] void init(); extern "C" [[noreturn]] void init();