#Zinnia

1 messages · Page 23 of 1

storm bobcat
#

literally almost impossible

hybrid island
#

Almost nobody makes use of it with an expression operand

#

But it does accept them

near tartan
#

it's only meant to check that a type exists and isn't forward declared

#

ASSERT_TYPE(uint64_t) for example

#

5000iq I'm aware

hybrid island
#

Wouldn't the compiler simply yell at your for not having the type be complete when you use it

near tartan
#

yeah ig i just wanted to make archdeps as easy to implement as possible

hybrid island
near tartan
#

i want this to run on many isas

hybrid island
#

You need shittons of semantic information to parse C++

#

I think if I had to choose a single programming language that should die (at least as it is), it's C++. Despite how much I hate on Java, C++ is clearly way more evil.

storm bobcat
#

C++ is fine

#

its just insanely complex

near tartan
#

which isn't fine

hybrid island
#

C++ is not fine exactly because it is insanely complex

storm bobcat
#

you dont have to understand it all

near tartan
#

I'll just say that c++ is poorly designed is all

hybrid island
#

It also gives us this gem:

hollow hedge
#

am I the only one who likes this forsaken language KEKW

near tartan
hybrid island
#

You don't just have rvalues and lvalues like in good old C

#

No, there's 3 more definitions here because why not

marsh holly
hybrid island
#

Biggest problem in C++ parsing is probably this here:

identifier identifier ()

This is simultaneously:

  1. An initializer for a variable
  2. A function definition
#

How do you distinguish these whilst parsing? It depends where in the code it appears :)

#

And what the first identifier is

storm bobcat
#

well, my point is that it wasnt designed to be this complex

#

it's just a result of its evolution

near tartan
#

fair enough

storm bobcat
#

I do like C++ and i believe if you use it right you can write very good code with it

hybrid island
#

Yeah but parsing it properly is a complete and utter semantics-dependent nightmare.

storm bobcat
#

yes

near tartan
#

i wonder how bad rust is parsing wise

#

minus proc macros

hybrid island
#

Rust parsing wise seems to be way easier than C++

#

But harder than C

#

But for a Rust frontend the parsing isn't the problem, it's the sheer scope of the language

#

C++ in Lily-CC is impossible on my own because parsing

#

Whereas Rust in Lily-CC is impossible on my own because borrow checker and trait solver

#

Who knows, maybe in the distant future there'll be like 10 active devs on it (this will never happen probably) and that would likely be enough to do one or the other of both of these.

near tartan
#

mrustc it

hybrid island
#

That neither borrow checks nor trait solves

#

Doing that is easy as shit

near tartan
#

exactly

hybrid island
#

I'd rather experiment with a custom language frontend

near tartan
#

being able to bootstrap rustc is huge still

#

damn

hybrid island
#

Maybe I'll go through the effort of implementing just barely enough C++ to compile mlibc successfully

#

But that would be the extent of it realistically

storm bobcat
#

that would still be very hard

#

itd be easier to just write your own libc lol

near tartan
#

here's a funny idea

#

user mode zinnia running on zinnia

hybrid island
#

Yes I am in fact mad that mlibc is written in C++

near tartan
#

rip

#

guess we need to write our own now

hybrid island
#

Writing own libc is not for now

near tartan
#

yeah

hybrid island
#

Complete waste of time

#

We can do it for the coolness bootstrapping points later I guess but you'd still quickly run into a lot of userspace software hard requiring C++

#

C++ specification as fucking 1800 pages long bruh ts pmo

#

Band-aid ass "fix" to the ambiguity

storm bobcat
hybrid island
#

But mlibc is so easy to port nooo

hollow hedge
hybrid island
near tartan
#

ig whole zinnia can be made freestanding

hybrid island
#

With these semantics a naive approach of "try parse declaration but don't consume any tokens if it fails" can work correctly

#

If followed immediately by "parse expression"

near tartan
#

the userspace will need c++ regardless for like any other program

#

even just mesa needs c++

#

(llvmpipe et al)

hybrid island
near tartan
#

good

hybrid island
#

They are the host, so they're not hosted.

near tartan
#

changing that then

#

I'll move klibc out and repurpose it then

#

oh right i can actually share it between the kernel and servers

#

since they'll use the freestanding std*.h files from the kernel as well

hybrid island
#

Watch my dumbass try making a C++ compiler after all of this shit anyway trl

near tartan
hybrid island
#

Anyway

#

I just looked at the clock and I made it 4 in the fucking morning again

#

@near tartan that means it's probably also bedtime for you trl

#

I'm going to piss off immediately

storm bobcat
near tartan
storm bobcat
#

I think managarm does it??

hybrid island
#

Managarm has a separate set of libraries for servers

near tartan
#

yes they do but they dont really use any features of it

#

only like malloc and shit

#

posix calls are forwarded to the kernel iirc

#

which is something i wont be doing

#

that means servers must be statically linked and have no interpreter

#

ill write a small set of crts that load the vdso before jumping to main() today

storm bobcat
near tartan
#

servers need to be able to run completely detached from the posix world

hybrid island
#

@near tartan do you ever plan on supporting an arch that doesn't use radix tree paging?

#

E.g. PPC?

near tartan
#

like what

#

hm

#

maybe

#

ppc is pretty aids from what i heard

hybrid island
#

Big-endian as well

near tartan
#

ew

#

i mean running on the wii would be hilarious

#

but 32-bit 🤢

#

why do you ask?

hybrid island
#

Because UVM has pmap be arch-specific

near tartan
#

that's fine ig

#

then we need to move the mapping bits to the arch impl

hybrid island
#

I was thinking something like renaming the current pagetable thing to pmap and relocating it

near tartan
#

sure

hybrid island
#

A lot of it can be shared for radix tree paging archs though so I'll see if I can't make that work

near tartan
#

the main archs i want to support are x86_64, aarch64, riscv64 and loongarch64

#

any other isas i don't know well enough to reason about them

hybrid island
#

loong64 is still radix tree paging though right?

near tartan
#

@lofty copper

#

think so though

lofty copper
#

it has normal-ish page tables, just switched in two (like in arm, I think)

#

(you can look at my paging code god)

near tartan
#

oh damn yeah even for arm we can't just use generic mapping code

lofty copper
#

But also you can do paging yourself, it has manual page walking

#

and has an mmu which caches invalid addresses

near tartan
#

like a negative tlb?

lofty copper
lofty copper
#

It broke my kernel in a funny way when I was porting

near tartan
#

skully

hybrid island
#

So we can't do fully generic pmaps either way

lofty copper
#

You can

hybrid island
#

Because they're all just barely different enough

lofty copper
#

Also it has 4 rings like x86 iirc

#

But paging does let you set different protections for them

near tartan
#

rate my klibc

hybrid island
#

wtf

#

Also this will compile to memcpy calling memcpy if the compiler doesn't inline for whatever reason

#

And you still have implicit memcpy happening because the compiler is allowed to call that period.

#

So any implicit memcpy is all of a sudden a stack overflow

#

You are like actually allergic to even just reusing what you had before or smth

near tartan
#

no but i thought it wouldn't optimize as well as using the compiler builtins with AVX and shit

#

because the existing thing is for the kernel without FPU

hybrid island
#

Why the FUCK do you want to use AVX in the kernel

near tartan
#

???

#

this is for the servers

hybrid island
#

Then it shouldn't be called klibc

near tartan
#

it's not called that

#

i just said it for some reason

#

xd

#

it's called libserver

#

it has _start and vdso parsing

hybrid island
#

Even still, I don't think doing this impl for these functions is exactly a great idea.

near tartan
#

okay then i'll reuse the kernel impl

hybrid island
#

Go nab them from mlibc or smth

near tartan
#

c++

#

do i just add the freestanding flags to the global project scope

storm bobcat
#

its just gonna stack overflow

storm bobcat
hybrid island
storm bobcat
#

if not then rep movsb

median forge
storm bobcat
#

or use simd intrinsics if you want meme

hybrid island
storm bobcat
near tartan
hybrid island
#

Basically, __builtin_memcpy is a compiler intrinsic

near tartan
#

i thought it just provides its own impl

hybrid island
#

No

#

You will either get a very dumb loop or a call to memcpy

near tartan
#

ok reverted

hybrid island
near tartan
#

i think my impl is already quite optimized

#

but ill test it in compiler explorer at some point

hybrid island
#

Optionally you could add the likes of rep movsb gated behind large size and x86

#

Don't think compiler explorer is the right benchmarking tool for that

near tartan
#

hm

hybrid island
#

I'm sure there's some benchmarking software for memcpy and friends out there

near tartan
#

flamegraph will be useful at some point

hybrid island
#

In lieu of that just try the uACPI benchmark with both and see which is faster

near tartan
#

tru

lofty copper
near tartan
#

good

#

then ill leave it to llvm to optimize

lofty copper
#

Though the kernel's impl didn't for some reason

storm bobcat
#

rep movsb is insanely fast

lofty copper
near tartan
#

memcpy_beeeg

hybrid island
#

But yeah anything bigger than maybe 512 bits of data do rep movsb

near tartan
#

i dont think i ever copy more than a page at a time

storm bobcat
storm bobcat
lofty copper
near tartan
#

but you need to save/restore anyways on task switches

storm bobcat
#

idk probably but I mean in raw performance in userspace SIMD is the fastest thing

hybrid island
storm bobcat
#

i just said that

#

though I think SIMD is still faster for the case of moving 32 bit integers

#

idk ive measured memcpy vs simd copy on my own graphics code and it was significantly faster

lofty copper
lofty copper
hybrid island
#

that's graphics

#

rep movsb is faster if the copies get proper big though

storm bobcat
#

it was pretty big

#

clearing a whole framebuffer

vast lotus
#

Only the ones that are variable size and usually small would benefit from having a no-rep-movsb path

lofty copper
vast lotus
#

For what it's worth, linux's memcpy unconditionally uses rep movsb (if cpuid reports fast rep movsb)

lofty copper
hybrid island
#

We're discussing in userspace

vast lotus
#

Oh I missed that part of the conversation then

median forge
vast lotus
#

the same way it reports any feature, there's a bit for it in one of the leaves

#

i think it's called ERMS or something like that?

near tartan
#

i wonder what the most elegant way of preventing endianess issues with mmio is

#

maybe something like

typedef struct { uint64_t val; } be64_t;
uint64_t be_to_host(be64_t value);
hoary cave
#

how did you go from hating on non-LE to worrying about endianess in a span of a single day

somber solar
#

lmao

hybrid island
#

With a plain integer operand type

near tartan
#

im not saying i will never ever target BE, i just hate it as a concept

#

LE is better

grave peak
#

thats why middle endian must return

#

so that both big and little endian people are unhappy

near tartan
#

pnp endian

magic charm
#

If C had branded types like Modula 3 or typescript I would use those but a struct like this is second best solution

magic charm
#

The compiler can make sure you do things right with these

near tartan
#

yeah and iirc the ABI is the same as a plain primitive

#

at least in the sysv callconv

hybrid island
near tartan
#

based

hybrid island
#

(Which is the cause of a known issue in Lily-CC I can't fix right now)

near tartan
#

rust taught me to create newtypes when the usage of a primitive isn't obvious

near tartan
#

no

modern hamlet
#

or well

#

no because network uses big endian

#

htolel and letohl

near tartan
#

htolol

brisk totem
#

i wrote code for that too except with more clang overloading jank

vast lotus
hybrid island
#

yeah but

#

we are not doing i386

brisk totem
#

32 bit x86 is shit anyway 🙃

lofty copper
#

just use c++ trl

vast lotus
#

the same thing applies to c++

lofty copper
#

you can do some shit with templates and casting from/to host endian types

#

so you just use it as a normal int?

storm bobcat
#

You can use stronger C++ typing in C

#

There's a flag

near tartan
#

oh?

storm bobcat
#

Not sure it cares about integer types like that tho

#

-Wc++-compat

near tartan
#

@hybrid island i did some changes to how initd and posixd are built

#

they're now freestanding and use a freestanding lib called libserver that contains vdso wrappers, crts, and a subset of libc

#

so now you can build all of zinnia without a cross compiler

hybrid island
#

cool

near tartan
#

hm

#

this vdso thing is really annoying when trying to implement syscalls

#

i basically need to change 6 code locations when i modify a call

#
  • headers
  • kernel
  • vdso
  • libserver
  • libc
  • where it's used
#

if i remove the vdso i only need

  • headers
  • kernel
  • where it's used
magic charm
#

maybe you could autogenerate it

vast lotus
#

aren't libserver and libc "where it's used"

marble salmon
#

I still don't understand what the advantage of a vdso is other than moving compatibility issues into userspace. But if you modify calls in breaking ways, you don't get that benefit anyway

#

Other than that, the last 3 things that you listed seem to be the same thing

near tartan
#

you have the functions themselves and the wrappers that invoke the vdso function pointer

vast lotus
#

that seems like a very strange way to do it

#

just include the vdso in the dynamic linker's repository

#

then you can compile against it as if it's a normal dylib

near tartan
vast lotus
#

so?

#

on linux the vdso serves a completely different role

near tartan
#

yeah but I don't have a real dynamic linker in my case

#

the servers are freestanding static executables

vast lotus
#

is this code on github? i'd like to take a look

near tartan
#

most of it is still local, but i can push it to a wip branch rn

vast lotus
#

resolving symbols from dylibs is 90% of the dynamic linker, so if you have that already turning the existing code into a proper rtld should be relatively easy

marble salmon
#

90% of the dynamic linker is dealing with ELF / gnu idiosyncrasies like load scope vs global scope meme

vast lotus
#

also i'm looking at mlibc's rtld code rn and it looks like at least on the libc side you don't need the wrappers at all since it's already injected into the repository

hybrid island
#

@near tartan just don't call vDSO functions directly from the servers but only through libserver? I don't see the problem here.

near tartan
#

libserver doesn't abstract the vdso calls beyond just wrapping the function pointer

near tartan
#

because that allocates memory

marble salmon
#

ld.so only needs around 10 sysdeps

#

so it can't be that much work even if it needs to go through function pointers

#

and monkuous is right that for libc it shouldn't be required

near tartan
#

it has to

#

how do you allocate memory for the vdso without syscalls

vast lotus
#

alr i'll take a look

near tartan
#

src/lib/server/vdso.c

marble salmon
#

I don't think it's a good idea to let ld.so depend on the vdso

#

depend in the sense of: doing direct calls into the vdso

#

It's fine for libc to do that

#

But for ld.so it just complicates the initialization code path and makes it more fragile for no good reason

hoary cave
#

but it's really cool when you do it that way meme

marble salmon
#

Saving 5 nanoseconds to avoid an indirect call when calling open() from ld.so is a questionable goal

vast lotus
#

it's not saving any runtime performance since even "directly" calling an imported function is an indirect call through the PLT

#

for rtld i agree it's not worth the effort

marble salmon
#

and the benefit of not resolving external symbols in ld.so is that ld.so is more robust against mishaps on the dev side

#

for example, we instantly knows that the dev fucked up if ld.so has a JUMP_SLOT

near tartan
#

i never said that it's practical or useful

#

i could just make the syscalls header only, then i don't need to deal with any of this

marble salmon
#

just use function pointers in ld.so and direct calls to the vdso in libc

#

I think this is mostly self inflicted pain on your side if you have 3 abstraction layers for a single syscall meme

near tartan
#

yeah

hybrid island
#

Why do you want to hide all your syscalls behind a vDSO anyway?

near tartan
#

cool factor ™

#

it's useless

hybrid island
#

burh

#

IMO it's not worth it even for cool factor

near tartan
#

already nuked it

vast lotus
#

it assumes it was linked into an otherwise-static executable that only depends on the vdso, but still

#

oh and it also includes an unrelated bugfix: _start messed up the stack alignment

near tartan
#

it did?

vast lotus
#

yeah

#

the sysv abi expects the stack to be 16-byte aligned when a function is called

#

aka the stack is 8 bytes off from being aligned when the function is entered (since the call insn pushes the return addr)

#

by using jmp to get to __zinnia_entry this push didn't happen and so the stack was erroneously aligned

#
@@ -43,7 +43,8 @@ void _start() {
 #ifdef __x86_64__
     asm volatile(
         "mov rdi, rsp\n"
-        "jmp %c0" ::"i"(__zinnia_entry)
+        "call %c0\n"
+        "ud2" ::"i"(__zinnia_entry)
     );
 #else
 #error "Unsupported architecture!"``` this is the hunk in question
near tartan
#

i thought it would already be aligned on _start

#

ooh wait the abi expects me to call a function

vast lotus
#

yea

near tartan
#

makes sense

#

insane work

#

bro casually drops a diff "fixed everything btw"

#

where does vdso_lib come from? do i put libvdso there?

#

oh wait fuck

#

it's not built

#

because it's part of the kernel

near tartan
#

bruh

#

yeah that's disabled if you don't do -Dbuild_kernel

#

i need to refactor that

#

or just always build everything

vast lotus
#

yeah i don't really understand the separation in the first place

near tartan
#

managarm cosplay

vast lotus
#

ah

near tartan
#

because thor takes so long to build

#

thanks mesonlsp

vast lotus
#

the vdso should be buildable independently from the kernel, you can always make it so that the vdso is unconditionally built

#

if you don't want to get rid of build_kernel/build_servers

#

the vdso linker script removes all zn_* weak aliases so i assume that would result in a linker error

near tartan
#

this is old code i have changed locally

#

back when i still used header only

vast lotus
#

ah ok

#

was wondering since i had to edit the vdso version script to get linking to work

near tartan
#

the mlibc that i have here uses the same logic to parse the vdso before it does __mlibc_entry

marble salmon
marble salmon
#

But because different parts are built with different compilation settings

vast lotus
#

i mean should as in "i don't see anything that prevents it", not "it's a good idea"

brisk totem
#

i mean yes there are situations where it cant be viable

#

like if you need it for symbols only then ofc you can build it

#

but if you need to know the addresses of things in the vdso in the kernel (e.g. for syscall trampoline checking) then obv you cant

near tartan
#

why?

#

rip is known on syscall entry

#

i can just check if it's inside the vdso map

brisk totem
#

not just somewhere in the vdso

#

depending on your design you might also need/want to bake the vdso into the kernel

near tartan
#

i objcopy the vdso into the kernel

marble salmon
#

what exactly is libserver?

hoary cave
#

syscall wrapper

near tartan
#

something like a mini libc

#

without any posix stuff

marble salmon
#

why not just use mlibc with modified sysdeps?

#

That's what I'd do

near tartan
#

smaller binaries

brisk totem
#

i mean you can just do -Wl,--gc-sections no?

near tartan
#

doesn't do anything

marble salmon
#

Not a very convincing argument lol

brisk totem
#

and -ffunction-sections -fdata-sections

near tartan
#

already tried

brisk totem
#

like you shouldnt have very big binaries

near tartan
#

it's still ~1.5MB for a hello world

brisk totem
#

did you strip

near tartan
#

that gets down to 1MB

marble salmon
near tartan
#

running servers with mlibc is fine itself, but i don't really see the need

brisk totem
#

so something is very wrong

#

why is musl 800k even

marble salmon
#

I disagree with that lol

brisk totem
#

its 6400 bytes

marble salmon
near tartan
#

well they are not regular posix programs

#

so in that sense they are special

marble salmon
#

You lose a lot by requiring a special environment for servers

brisk totem
lofty copper
vast lotus
marble salmon
#

For example on Managarm you can just write servers in Rust or use the STL

vast lotus
#

it only links itself (and thus the server it is built into)

brisk totem
#

even if they are just special because they use the native subsystem and not the posix subsystem

vast lotus
#

and only with the vdso

near tartan
brisk totem
#

tbh nostd rust is better anyway

#

alloc sucks

lofty copper
marble salmon
#

That's a stupid argument

brisk totem
#

imo treating servers specially ends up being useful anyway

marble salmon
#

Everything "can" be nostd, that doesn't mean that it's useful

brisk totem
#

but i would also very much write nostd code on linux for system level stuff to make sure you can handle alloc failures

near tartan
#

i can imagine that most of the time i'd just end up using direct syscalls anyways

brisk totem
#

tbh a lot of things in the C++ STL arent things i'd want to use either

#

and the rust std is nice as an OS abstraction, but if you have only one OS its usefulness is not crazy?

brisk totem
marble salmon
#

The usefulness is that you can re-use existing code without NIHing everything

brisk totem
#

i mean in rust you can do that with no_std!

#

a huge amount of rust libraries do work no_std if you have alloc

near tartan
#

if i can get mlibc to not be huge as fuck, i'd use it

marble salmon
#

In rust you're arguably in a better spot but still

#

Everything that needs to sleep uses std

brisk totem
marble salmon
#

Every EBR implementation uses std

brisk totem
marble salmon
#

Almost every async executor uses std

#

Epoch based reclamation

brisk totem
brisk totem
#

because your os primitives likely dont integrate with tokio

marble salmon
#

You're arguing with theoretical advantages while ignoring practical benefits

brisk totem
#

and the only one anyone else integrates with is tokio

brisk totem
marble salmon
#

Show me the OS that has actually NIHs this stuff and that did it well enough such that the "my NIH is faster" actually materializes

#

Your argument breaks down once you consider that rewriting all of tokio/crossbeam/smol/rayon with the same quality of implementation just won't happen

brisk totem
#

i mean doesnt managarm have its own async executor

#

also if your server needs rayon type concurrency. idk i feel like there are other problems

marble salmon
near tartan
#

lol

brisk totem
#

and the stuff you can reuse is often not terribly well written

marble salmon
#

Also, we're reusing the data structures from smol

#

so stuff like async-channel etc

brisk totem
#

makes sense

marble salmon
#

I also never said: drivers should be posix programs, i said: drivers can use a libc with separate bindings

brisk totem
#

i mean yeah sure

lofty copper
brisk totem
#

and std::bad_alloc can work in OOM but its awfully hacky

#

and i dont want implicitly checked allocation failures

vast lotus
#

ah yes the emergency buffers bs

lofty copper
#

But it's better that "the memory is infinite" and if it isn't just crash

brisk totem
#

better for what

grave peak
#

unless ur a db or something

lofty copper
#

but what about microkernels and drivers

brisk totem
#

imo its not really okay for drivers

grave peak
#

for drivers yeah

lofty copper
#

and servers

#

I don't want something critical to just die because userspace can just die at will

#

(like yes, there are issues with stack and cow and stuff, but still)

marble salmon
#

It depends

lofty copper
marble salmon
#

Treating small allocations as infailable in drivers can be fine

#

If there are other mechanisms to constrain memory footprint

#

For example, if the allocation size per concurrent request is bounded, you can limit concurrency instead of limiting memory

lofty copper
#

But still, even if they fail, you can return an error, instead of just dying completely

brisk totem
near tartan
#

I'm so torn now 😭

lofty copper
#

just use both trl

#

I mean my "important" servers are in C

near tartan
#

ig i can do what korona said and make it so rtld uses the function pointer wrapper abstraction, and mlibc proper uses the vdso like a normal dso

#

but that's also ugly as fuck

marble salmon
#

Don't you have to do that for posix userspace anyway?

near tartan
#

yeah im just talking in general now

#

if servers and posix userspace uses mlibc

#

ideally i would like rtld to use the same DSO logic like @vast lotus wrote

vast lotus
#

the self-relocation thing for libserver?

near tartan
#

yea

vast lotus
#

it should work perfectly fine for rtld as well

near tartan
#

if i use mlibc for servers, there's no point in duplicating the logic in libserver

lofty copper
#

but what was the original issue with not using mlibc for servers?

near tartan
#

being 1MB in a static build

hybrid island
#

what

near tartan
#

even with stripping and --gc everything

marble salmon
#

Did you debug why this happens?

near tartan
#

i spent an evening trying to figure it out

#

i'll debug more ig

near tartan
#

I don't think I'm doing this correctly

magic charm
#

even some monolithic kernels rely on having certain kernel workers having VM privilege to allocate when all others can't allocate

near tartan
#

hmmmmmmmmmmmmm

#

i can't do -static-pie because of rcrt1.o

#

i can't do -static because of the vdso code

vast lotus
#

what's preventing you from making mlibc install rcrt1.o

#

or changing your gcc configuration to not use it

near tartan
#

idk what it is

#

no sysdep has a rcrt1

#

and the disasm from glibc isnt very helpful

vast lotus
#

it's just a crt1 suitable for inclusion in static pies

neon flicker
#

yes it is you can copy it

#

duh

near tartan
#

how?

#

it's glibc code

vast lotus
#

this is the gcc spec fragment that selects the crt1 to use

#

if your existing crt1 is simple enough and uses rip-relative addressing, you can just make all the various crt1s symlinks to that one

hybrid island
#

Why are you still insisting on the vDSO despite saying you don't need it

neon flicker
near tartan
#

jfc

vast lotus
#

but in any case -static-pie has the same dylib restriction as -static

near tartan
#

ok but then all of this is kinda pointless

near tartan
#

and monkuous went through the trouble of writing the patch so i want to at least test it

vast lotus
#

this is the way i got static/static-pie linking to work in proxima while still dynamically linking the vdso

hybrid island
#

It's probably best to make a Zinnia servers GCC anyway

vast lotus
#

basically you have to ensure that the linker command line has -l<vdso> before -static, which to my knowledge can only be done by editing the gcc spec strings

near tartan
#

this is cancer

vast lotus
#

yep

near tartan
#

why do i bother with anything 😭

hybrid island
#

BRUH JUST MAKE IT A ONE HEADER LIBRARY

near tartan
#

yeah

vast lotus
#

elf toolchains really aren't designed with this use case in mind

hybrid island
#

And those are just syscall helpers and that's it

near tartan
#

i hate having public C headers with nonstandard C, but i guess there's no way around it

#

i cant make a static library and just depend on it anyways, because then libc.a doesn't contain those symbols

hybrid island
near tartan
#

rip

#

whatever

#

ftr @vast lotus your codee worked

hybrid island
#

I have literally not seen a single project that sticks entirely to standard C + assembly

vast lotus
#

i mean yeah i tested it

near tartan
#

the impl can have it

#

it's not that deep

hybrid island
#

Surely not

#

Lily-CC, clang and GCC (among others) will definitely support the extensions you need

#

glibc is FULL of GNU extensions

near tartan
#

autism brain ig

hybrid island
#

(on a language level that is, library as well)

near tartan
#

ill change it to header only

near tartan
#

okay that's done

#

but now initd is 1mb again

#

without lto there's basically no difference

#

also tried

        '-fdata-sections',
        '-ffunction-sections',
        '-Wl,--gc-sections',
#

that doesn't change anything either

hybrid island
#

How is that a thing

#

Something in mlibc must be depending on all the functions unconditionally or smth

near tartan
#

oh wait

#

libc.a might have to be compiled with that

hybrid island
near tartan
#

galaxybrain

hybrid island
#

otherwise it'll just collect everything anyway

near tartan
#

why is that not defaultnooo

hybrid island
#

some bullshit

vast lotus
#

specifically without -fdata-sections -ffunction-sections it'll include everything in every object file that gets included

vast lotus
hybrid island
#

fair

vast lotus
#

or some attempt to keep related globals together for cache locality or something

near tartan
#

gnu::hot

#

idk

vast lotus
#

true

#

forgot about that, probably compat then

near tartan
#

what exactly does the flag do anyways

vast lotus
#

puts each function/global in its own section instead of just .text/.rodata/.data/.bss

#

the linker gc works on the section level so that means each function/global can get gc'd individually

#

for example with -ffunction-sections int foo() would get put in .text.foo whereas without it it'd get put in .text

near tartan
#

ah, so that requires the default lds to contain something like .text, .text.* right?

vast lotus
#

yeah

hybrid island
#

That is what the .* matches in the linker scripts

near tartan
#

smort

#

inb4 1000 sections

hybrid island
#

Well you have e.g.

.text {
  *(.text .text.*)
}

That will combine all of them after GC'ing them

near tartan
#

yeah but not in libc.a KEKW

hybrid island
#

You don't link libc.a

#

It's an ar-style archive of object files

near tartan
#

wtf is this

#

i keep seeing libsmarter failures

vast lotus
#

do you not have libstdc++?

near tartan
#

i do

vast lotus
#

it should provide cassert

near tartan
#

and it literally compiled mlibc before

#

but when i add this i get the cassert fail

vast lotus
#

you're overriding the variable

#

maybe try appending to it?

near tartan
#

oops

#

copy paste mistake

#

okay nice

#

that did the trick

#

still kinda big tbh

#

228kb

#

but this is already much better

#

nice

marble salmon
#

what does nm --print-size --size-sort <your binary> | tail print?

near tartan
#
marvin@aquaduct ~/r/z/build-x86_64 (main)> nm --print-size --size-sort system-root/boot/initd | tail
nm: system-root/boot/initd: no symbols
marvin@aquaduct ~/r/z/build-x86_64 (main)> 
marble salmon
#

before stripping

near tartan
#
marvin@aquaduct ~/r/z/build-x86_64 (main)> nm --print-size --size-sort pkg-builds/zinnia-servers/servers/initd/initd | tail
0000000000421c80 000000000000135b T _ZN5mlibc7nl_timeC1Ev
0000000000421c80 000000000000135b T _ZN5mlibc7nl_timeC2Ev
0000000000415e80 0000000000001846 T _ZN16ObjectRepository12_parseVerdefEP12SharedObject
000000000041c040 0000000000001c9a t _ZN6Loader23_processLazyRelocationsEP12SharedObject.part.0
000000000041eb00 0000000000002072 T _ZN6Loader13_buildTlsMapsEv
000000000040f4c0 0000000000002275 T interpreterMain
000000000042c348 0000000000002288 r __EH_FRAME_BEGIN__
0000000000432380 00000000000023c0 b _ZN12_GLOBAL__N_1L14startingLocaleE
0000000000434740 00000000000023c0 b _ZN12_GLOBAL__N_1L7cLocaleE
0000000000436b20 0000000000006000 b _ZN12_GLOBAL__N_1L12key_globals_E
marvin@aquaduct ~/r/z/build-x86_64 (main)> 
marble salmon
#

key_globals could potentially use dynamic allocation I guess (?)

#

not sure why we need both cLocale and startingLocale

near tartan
#

@fair lintel maybe?

hybrid island
#

Damn I wish my brain wasn't fogged up

#

I wanted to program for this today FeelsBadMan

near tartan
#

anyways

#

it cant find _start anymore 🔥

hybrid island
near tartan
hybrid island
#

Is this kernel?

near tartan
#

ye

hybrid island
#

I'm assuming this is because you're now doing -ffunction-sections and -Wl,--gc-sections in the kernel?

near tartan
#

i don't use the former in the kernel yet

hybrid island
#

Oh

#

Did you forget to extern "C" in a C++ translation unit?

near tartan
#

it's plain C meme

hybrid island
#

well anyway my brain is mush gl debugging

near tartan
#

thx

#

i dont even see any object files

#

let me put a verbose on

hybrid island
#

inb4 accidentally removed the srcfile trl trl

near tartan
#

💀 wtf

hybrid island
#

That

#

Doesn't even contain .text

vast lotus
#

is that the final executable or an object file

near tartan
#

final executable

vast lotus
#

i'm guessing that, because it couldn't find the entry point, nothing is reachable from any gc root

near tartan
#

fixed it

#

it happened again lmfao

hybrid island
#

XD

#

GJ

near tartan
#

i was rearranging meson builds and didnt adjust their usages

#

this used to be klibc_sources =

#

🗣️

hybrid island
#

So how does mlibc for the servers work then

#

Kinda chicken-and-egg problem

near tartan
#

servers must not make any posix calls

hybrid island
near tartan
#

ye

#

but you can still use a lot of functions tbh

#

let me try malloc

#

also the entire printf suite

hybrid island
#

How would printf even work

#

You don't have FDs for servers

#

So where does that go

near tartan
hybrid island
#

right

#

For some reason this makes me think of that one guy who made a game that runs entirely using a single printf

hybrid island
marble salmon
near tartan
#

yea that's what i do

hybrid island
#

That's probably for the best

near tartan
#

tho idk how to do that conditionally

#

as in, how do i enforce that for servers

hybrid island
#

Make some mlibc compile flag ig

#

Like it doesn't really make sense using the same exact mlibc for both

vast lotus
#

yeah you'd probably need a separate mlibc build for that

near tartan
#

let me push the current kernel + mlibc state

#

this seems to be working

hybrid island
#

I wonder how Managarm itself does this

near tartan
#

mini posix in the kernel

hybrid island
#

That's... Interesting.

marble salmon
#

It doesn't really implement posix in the mini posix

#

It allows a program to open its DSOs and to allocate

#

We'll probably move this into userspace at some point

hybrid island
marble salmon
#

wdym by "special syscalls"

hybrid island
#

Dedicated syscalls just for the mini posix

marble salmon
#

the mini posix just implements a part of the posix protocol (the part corresponding to what i wrote above) and it fails every other request

near tartan
#

does mlibc not work with lto?

vast lotus
#

iirc gcc's lto is somewhat buggy when builtin functions (like memset) are defined in one of the lto'd translation units

near tartan
#

phenomenal

hybrid island
#

bruh

#

Another problem to solve in Lily-CC trl

marsh holly
hybrid island
#

LTO memset is illegal apparently

vast lotus
#

idk i never managed to reduce it to an actual minimum reproducible example so i can't be sure that's actually the issue

hybrid island
#

You could just disable LTO for just the impl of string.h ig

vast lotus
#

but it's certainly the only type of project i've encountered those types of lto bugs on

marsh holly
#

damn

near tartan
#

@hybrid island i have updated everything

#

the distro too

hybrid island
#

Cool I shall DOWNLOAD

#

And see if I can't build it

#

After several ID10T errors we compiling image shit again

#

Other problem is:

../../../src/ports/mlibc/meson.build:385:22: ERROR: Include dir options/bsd/include does not exist.
#

I already did a complete cleanbuild

near tartan
#

you need a cross compiler

#

for the servers

#

kernel can still use any freestanding compiler

hybrid island
#

Do you have the cross compiler for me anywhere?

near tartan
#

wdym

hybrid island
#

Patches and shit I need to get the cross compiler

#

Because it's not the same one as userspace, is it?

near tartan
#

it is

#

i use the same gcc

hybrid island
#

oh

#

ok

near tartan
#

the kernel is freestanding

hybrid island
#

What about the mlibc missing include though

near tartan
#

you should be able to just build it with xbstrap

near tartan
#

from your host

hybrid island
#

oh yeah it is

#

but why

near tartan
#

because you're not using xbstrap

#

probably

hybrid island
#

Wait do I not build the kernel and servers standalone anymore now?

hybrid island
#

This looks like wrong mlibc

#

Or something

near tartan
#

try nuking the ports dir (or just the mlibc dir)

near tartan
#

i can show you how to set up LSP in vc at some point too

#

(for mlibc and servers etc)

hybrid island
#

that would be good

near tartan
#

that's why i'm using xbstrap btw

#

it can forward clangd to the host

hybrid island
#

Because LSP setup is easier

#

ic

#

Ok it got past the error

#

Building GCC once more

near tartan
#

for reference, it's the same setup as with managarm, except the script is in support/lsp-launcher.sh

hybrid island
#

Well I haven't worked on Managarm before either

near tartan
#

there's a handbook

hybrid island
#

Only promised to do FAT filesystem and promptly forgot trl

#

Wait they still don't have it

#

And that means I still make good on that promise

#

What

#

Why are we already cross-compiling CMake?

#

lmao

near tartan
#

zstd

#

because i had the recipe already xd

hybrid island
#

-- Installing: /var/bootstrap-zinnia/build/tools/host-cmake/share/cmake-4.2/ That's CMake

#

Not zstd

near tartan
#

yeah i know

#

we're compiling it for zstd

hybrid island
#

Oh this is a host package

near tartan
#

ye

#

debian packages are usually out of date so im not taking any risks

hybrid island
#

Oh god we're building LLVM too

marble salmon
#

why are you not running it through xbstrap emma?

hybrid island
#

I really am compiling C compilers all day smh

hybrid island
marble salmon
#

ah

hybrid island
#

I thought that the servers had to be built separately

#

but no they're in the xbstrap

#

thingimajig

near tartan
#

YOOOO I GOT IPC WORKING

hybrid island
#

Anyway I'll report back in several hours when LLVM is done 💀

hybrid island
near tartan
hybrid island
#

I have 24GiB on this machine that should be just enough

near tartan
#

ah that's fine

hybrid island
#

Unless they made LLVM even bigger

near tartan
#

nah we only compile a bit

hybrid island
#

Last time LLVM is when I tried (and failed) to add a backend to it

near tartan
#

@hoary cave

#

oops

marble salmon
#

how will zinnia ipc work?

near tartan
#

rn it's just very simple synchronous message passing

hybrid island
#

Can I add doors later?

near tartan
#

yes

hybrid island
#

That sounds very cool

#

For doors I was thinking of going with the approach of having the receiver create a thread pool on-demand

#

Maybe with a system call along the lines of zn_door_accept to accept a single door-call using the current thread

near tartan
#

FTR i've no idea what doors are or what they do besides they're from solaris

hybrid island
#

It has a door return stack in the kernel for, well, returning from door calls.

near tartan
#

i want to do a lot of shared memory ipc too

#

i think there's a lot of potential to be had

hybrid island
#

shmem ipc is much more of a userspace thing

near tartan
#

yeah

hybrid island
#

all you should need is a handle type for shared memory, which is easily made

near tartan
#

and saves you a ton of syscalls and context switches if you can sync it properly

marble salmon
hybrid island
#

Oh BTW because the VMM is going to be UVM-like, I'd like to see if we can do some cool things like page leasing

#

Where basically the receiver accepts a CoW view of the memory passed to it

#

I also had a slightly alternative idea for implementing fork(): Don't have the kernel clone the calling thread's registers, let userspace do that. You need to clone a bunch of handles anyway. This way, we can make the syscall fastpath a lot faster because there is no more need for modifying the registers before returning.

near tartan
#

if it works, sure

hybrid island
#

TL;DR: For how I'd implement this is that you actually only create a CoW clone of your current memory map, then you create a new process and a thread within with the same old stack and registers.

hybrid island
somber solar
#

nice

hybrid island
#

I finally got sick of BadgerOS and then Marvin happened to start a microkernel project at basically the same time as me

#

So now we're here

near tartan
#

yeah

hybrid island
#

What was going to be that microkernel instead became the template for the Rust Limine bindings

#

BTW don't you just love seeing a warning like this come out of LLVM codebase?

/var/bootstrap-zinnia/src/ports/llvm/llvm/include/llvm/ADT/APInt.h:192:18: warning: ‘void operator delete [](void*)’ called on a pointer to an unallocated object ‘1’ [-Wfree-nonheap-object]
  192 |       delete[] U.pVal;
      |                  ^~~~
near tartan
#

happens when you use gcc to compile llvm

#

ofc they themselves never do that meme

hybrid island
#

It's still a warning

#

About an invalid free

near tartan
#

yeah but it doesn't pop up in llvm

#

only in gcc

#

llvm has many of these in their code

hybrid island
#

I'm now 4150/5267

near tartan
#

lfg

hybrid island
#

compiling LLVM

near tartan
#

i'm working on something akin to managarm's mbus

#

though i still don't really understand their code

hybrid island
#

core contributor trl

near tartan
#

yeah i mostly worked on eir and thor

#

so far

hybrid island
#

fair

near tartan
#

the mbus code is pretty cryptic and few docs

#

as i understand it it's like a telephone operator

hybrid island
#

Yeah

#

We should ensure our docs are a little better than "just read the code bro"

near tartan
#

yeah i want good docs

#

thinking about ipc design...

#

i want initd to be the main networking hub

hybrid island
#

wdym networking

near tartan
#

not internet networking

hybrid island
#

Sharing handles to channels etc?

near tartan
#

like ipc routing

#

yeah, like if you want to connect to another server in the domain

#

you would then ask initd to create a connection on your behalf

#

as in, initd gets special treatment in many aspects of the system

hybrid island
#

Initd gets to do things other processes need authorization for?

near tartan
#

not necessarily

#

initd just has the connections established already

hybrid island
#

So you start up with a channel to initd

#

And you ask it for the rest

near tartan
#

yes

hybrid island
#

hmm

#

Microkernel FUSE right

#

Is gonna be much easier

#

Because all TS is userspace anyway

near tartan
hybrid island
#

YOOO XBSTRAP BUILD FINISHED

near tartan
#

baller

hybrid island
#

Why does empty-image need root

#

None of this should

#

Use fakeroot

near tartan
#

same applies to parted and mkfs.*

hybrid island
#

And what? /usr/sbin is not executable by the user?

near tartan
#

no but it isn't guaranteed to be there

#

ig i'd have to push /usr/sbin to PATH

hybrid island
#

That is quite possibly the stupidest reason to need sudo I've heard from you

near tartan
#

yeah

#

but is pushing to PATH an alternative?

#

limine also does this iirc

hybrid island
#

Uh what

#

Not a single sudo in limine-c-demo

near tartan
#

i am talking about limine

hybrid island
#

That's dumbassery

near tartan
#

idk

hybrid island
#

I'll get rid of these instances of sudo

near tartan
#

it's the simplest fix

hybrid island
#

The way I last built my image is way different and doesn't need sudo

near tartan
#

and like i said, i guess instead you'd add /usr/sbin/ to PATH

hybrid island
#

adding sbin to path is just not our problem really

near tartan
#

???

#

so you don't want this to work then

#

i dont get it

hybrid island
#

well you also need sudo for losetup right

near tartan
#

no idea

#

on opensuse i need sbin to be in PATH so it can find the programs lol

#

and running as sudo has sbin already in PATH

#

how did you build your image

hybrid island
#

Yeah sudo for losetup

near tartan
#

and the rest?

hybrid island
marble salmon
#

you can just do PATH=$PATH:/sbin losetup

near tartan
#

that's what i suggested

hybrid island
#

Still need sudo

#

Otherwise losetup acts dumb as says not found

marble salmon
#

well yeah

near tartan
#

ok so the discussion is pointless anyways 😭

#

if you need sudo for one command it doesn't matter for the other ones, right?

hybrid island
#

That's the thing: My image creation doesn't need anything privileged

#

Yours does

#

And we could easily re-use mine for this to fix this

somber solar
#

you can create a disk image without sudo

near tartan
#

but does yours replicate the mount tree

hybrid island
#

UIDs?

#

Yes

near tartan
#

no

#

the mount tree

#

like partitions that are mounted somewhere in the rootfs

#

some files are installed to /boot for example

#

but ofc that's the ESP, and not the rootfs

hybrid island
#

I symlink those then replace the symlink with an empty dir just before making the image from the sysroot

marble salmon
somber solar
#

found the script
I was messing with stuff and wrote it a few months ago

hybrid island
#

shit

somber solar
#

oof

hybrid island
#

I thought that would upload as a file

#

This here is how I combine the created filesystem blobs

#

(Marvin this is on the Positron repo, but the others can't see that because not public)

near tartan
#

this seems much more complex for relatively little reward imo

#

i agree that i should get rid of the sudos

hybrid island
#

Actually the reason this is more complex is because having it be too simple caused problems in the past

#

This way lets me very easily add/remove/resize partitions

somber solar
#

I'll save a link to those messages in my todo list :P

hybrid island
#

And I tested it too

#

So another change I propose is that I bring these here in for image creation so we don't need sudo at all.

near tartan
#

it might be easier to do this in a python script tbh

#

then you have less stupid integer handling

hybrid island
#

Oh probably

#

But this is already here

near tartan
#

also i use truncate instead of dd

#

so the image isn't actually that big

hybrid island
#

Not sure you can copy the blobs in while still having the holes of zeroes

near tartan
#

that's the downside

#

it's probably also a tick slower

hybrid island
#

Because the FS formatting tools don't support any offsets

#

Let me ask the clanker

near tartan
#

for example

#

this 4gb image is much smaller on disk

hybrid island
#

Apparently dd conv=sparse should do it but it isn't for some reason

#

lmao didn't remove old dd without sparse hang on

#

Yeah

#

I will submit a PR with an UPGRADED version of this soon ok?

near tartan
#

ok

#

do consider putting this in a python script :3

#

just because i hate bash and its fucking insane syntax

hybrid island
#

Yeah I can do that

#

Do you wanna VC btw?

near tartan
#

im in managarm rn

hybrid island
#

mnaganarm

near tartan
#

mangam

near tartan
#

encoding multiple non-fixed-size strings is not the most trivial thing tbh

#

maybe there's something cool i can do with macros

hybrid island
near tartan
#

obviously

#

but im talking about userspace

#

this is how it looks for the sender

hybrid island
#

Yeah this is gonna need some utilities very soon

near tartan
#

and i'm wondering how one could start doing that

hybrid island
#

And I'm making the pythoM scriBt

near tartan
#

YOOOOOOOOOOOOOOOOOOOOOOOO

#

i can create new channels and pass handles over to another process

hybrid island
#

oh god there's fancy colors how much did you overengineer it

near tartan
#

nothing

#

i just added a few ansi escape codes to the printf

hybrid island
#

Also I have an image creator pythom

near tartan
#

bored 100

#

it's just to test anyways

#

im not committing ts

hybrid island
#
(venv) LinuxBot build$ du -h --apparent-size zinnia.img 
4.0G    zinnia.img
(venv) LinuxBot build$ du -h zinnia.img 
20M     zinnia.img
(venv) LinuxBot build$ 

That also works now btw

#

Commit time

near tartan
#

you need to remove old tasks when you delete other files