Make kernel build with clang.

It's a bit faster than g++ and seems to generate perfectly fine code.
The kernel is also roughly 10% smaller(!)
This commit is contained in:
Andreas Kling 2018-11-09 12:20:44 +01:00
parent 7b3b5f745f
commit ebf308d413
10 changed files with 40 additions and 27 deletions

View file

@ -114,31 +114,31 @@ struct IsPointer : __IsPointerHelper<typename RemoveCV<T>::Type> { };
template<class> struct IsFunction : FalseType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...)> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args......)> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...)> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) const> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args......) const> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) volatile> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args......) volatile> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) volatile> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) const volatile> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args......) const volatile> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const volatile> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args......) &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) const &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args......) const &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) volatile &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args......) volatile &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) volatile &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) const volatile &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args......) const volatile &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const volatile &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args......) &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) const &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args......) const &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) volatile &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args......) volatile &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) volatile &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) const volatile &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args......) const volatile &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const volatile &&> : TrueType { };
template<class T> struct IsRvalueReference : FalseType { };
template<class T> struct IsRvalueReference<T&&> : TrueType { };

View file

@ -29,9 +29,7 @@ static inline size_t allocationSizeForStringImpl(size_t length)
RetainPtr<StringImpl> StringImpl::createUninitialized(size_t length, char*& buffer)
{
if (!length)
return theEmptyStringImpl();
ASSERT(length);
void* slot = kmalloc(allocationSizeForStringImpl(length));
if (!slot)
return nullptr;
@ -52,6 +50,8 @@ RetainPtr<StringImpl> StringImpl::create(const char* cstring, size_t length, Sho
char* buffer;
auto newStringImpl = createUninitialized(length, buffer);
if (!newStringImpl)
return nullptr;
memcpy(buffer, cstring, length * sizeof(char));
if (shouldChomp && buffer[length - 1] == '\n') {
@ -108,6 +108,8 @@ RetainPtr<StringImpl> StringImpl::toLowercase() const
slowPath:
char* buffer;
auto lowercased = createUninitialized(m_length, buffer);
if (!lowercased)
return nullptr;
for (size_t i = 0; i < m_length; ++i)
buffer[i] = toASCIILowercase(m_characters[i]);
@ -128,6 +130,8 @@ RetainPtr<StringImpl> StringImpl::toUppercase() const
slowPath:
char* buffer;
auto uppercased = createUninitialized(m_length, buffer);
if (!uppercased)
return nullptr;
for (size_t i = 0; i < m_length; ++i)
buffer[i] = toASCIIUppercase(m_characters[i]);

View file

@ -42,7 +42,6 @@ private:
void computeHash() const;
size_t m_length { 0 };
bool m_ownsBuffer { true };
mutable bool m_hasHash { false };
const char* m_characters { nullptr };
mutable unsigned m_hash { 0 };

View file

@ -49,7 +49,7 @@ bool ELFLoader::layout()
}
});
m_image.for_each_section_of_type(SHT_PROGBITS, [this, &failed] (const ELFImage::Section& section) {
m_image.for_each_section_of_type(SHT_PROGBITS, [this] (const ELFImage::Section& section) {
#ifdef ELFLOADER_DEBUG
kprintf("ELFLoader: Copying progbits section: %s\n", section.name());
#endif

View file

@ -55,19 +55,19 @@ BOOTLOADER = Boot/boot.bin
IMAGE = .floppy-image
ARCH_FLAGS =
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib #-nostdinc
KERNEL_FLAGS = -ffreestanding -fno-stack-protector -fno-ident
KERNEL_FLAGS = -ffreestanding -fno-stack-protector -fno-ident -fno-builtin
WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings
FLAVOR_FLAGS = -mregparm=3 -march=i386 -m32 -fno-exceptions -fno-rtti -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
OPTIMIZATION_FLAGS = -Os -fno-asynchronous-unwind-tables
OPTIMIZATION_FLAGS = -Oz -fno-asynchronous-unwind-tables
INCLUDE_FLAGS = -I.. -I.
SUGGEST_FLAGS = -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override #-Wsuggest-attribute=noreturn
#SUGGEST_FLAGS = -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override #-Wsuggest-attribute=noreturn
DEFINES = -DSERENITY -DKERNEL -DSANITIZE_PTRS
CXXFLAGS = $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(KERNEL_FLAGS) $(FLAVOR_FLAGS) $(ARCH_FLAGS) $(STANDARD_FLAGS) $(SUGGEST_FLAGS) $(INCLUDE_FLAGS) $(DEFINES)
#CXX = /usr/local/gcc-4.8.1-for-linux64/bin/x86_64-pc-linux-g++
#LD = /usr/local/gcc-4.8.1-for-linux64/bin/x86_64-pc-linux-ld
CXX = g++-8
CXX = clang
LD = ld
LDFLAGS = -T linker.ld --strip-debug -melf_i386 --gc-sections --build-id=none -z norelro -z now

View file

@ -52,7 +52,8 @@ private:
PhysicalAddress m_paddr;
};
struct PageDirectory {
class PageDirectory {
public:
dword entries[1024];
RetainPtr<PhysicalPage> physical_pages[1024];
@ -91,7 +92,8 @@ private:
Vector<RetainPtr<PhysicalPage>> m_physical_pages;
};
struct Region : public Retainable<Region> {
class Region : public Retainable<Region> {
public:
Region(LinearAddress, size_t, String&&, bool r, bool w, bool cow = false);
Region(LinearAddress, size_t, RetainPtr<VMObject>&&, size_t offset_in_vmo, String&&, bool r, bool w, bool cow = false);
Region(LinearAddress, size_t, RetainPtr<VirtualFileSystem::Node>&&, String&&, bool r, bool w);

View file

@ -3,6 +3,8 @@
#include "kmalloc.h"
#include <AK/Types.h>
extern "C" {
void memcpy(void *dest, const void *src, DWORD n)
{
BYTE* bdest = (BYTE*)dest;
@ -71,8 +73,10 @@ int memcmp(const void* v1, const void* v2, size_t n)
return 0;
}
extern "C" void __cxa_pure_virtual() NORETURN;
extern "C" void __cxa_pure_virtual()
void __cxa_pure_virtual() NORETURN;
void __cxa_pure_virtual()
{
ASSERT_NOT_REACHED();
}
}

View file

@ -2,6 +2,8 @@
#include "types.h"
extern "C" {
void memcpy(void*, const void*, DWORD);
void strcpy(char*, const char*);
int strcmp(char const*, const char*);
@ -10,3 +12,5 @@ void *memset(void*, BYTE, DWORD);
char *strdup(const char*);
int memcmp(const void*, const void*, size_t);
char* strrchr(const char* str, int ch);
}

View file

@ -8,7 +8,7 @@ extern "C" void syscall_entry(RegisterDump&);
extern "C" void syscall_ISR();
extern volatile RegisterDump* syscallRegDump;
asm volatile(
asm(
".globl syscall_ISR \n"
"syscall_ISR:\n"
" pusha\n"

View file

@ -824,7 +824,7 @@ bool Ext2FileSystem::setBlockAllocationState(GroupIndex group, BlockIndex bi, bo
ASSERT(block);
auto bitmap = Bitmap::wrap(block.pointer(), block.size());
bool currentState = bitmap.get(bitIndex);
kprintf("ext2fs: setBlockAllocationState(%u) %u -> %u\n", block, currentState, newState);
kprintf("ext2fs: setBlockAllocationState(%u) %u -> %u\n", bi, currentState, newState);
if (currentState == newState)
return true;