ChanServ changed the topic of #zig to: zig programming language | https://ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
frmdstryr has quit [Ping timeout: 260 seconds]
frmdstryr has joined #zig
msingle has joined #zig
<andrewrk> marler8997, I published the code: https://github.com/andrewrk/zig-window
<andrewrk> I could use some help troubleshooting figuring out why it is crashing after the execve for me
<marler8997> looking
<andrewrk> you said it worked with your c code with -fPIE right?
<marler8997> I'll have to look to see if I used pie or not..checking
<marler8997> I used zig cc, what's zig cc's default?
<andrewrk> no pie
<marler8997> my example that doesn't use libc, I don't think it needs to be pie
<marler8997> but...someone doesn't work when I call into libc, I never figured out what that was
<marler8997> I can call into a custom built so file, but didn't get libc working
<marler8997> do you have a zig branch you're working from?
msingle has quit [Ping timeout: 260 seconds]
<andrewrk> marler8997, master branch - I also put the sha1 in the readme
<andrewrk> maybe PIE was a red herring
nvmd has quit [Quit: Later nerds.]
<andrewrk> marler8997, what's up with libfoo.so in your reloader project? what purpose does it serve?
<marler8997> so test that I can call functions from shared libraries
<andrewrk> I see
<marler8997> I wanted to start with the simplest example possible, and be able to control how the .so file is built
<andrewrk> are you getting the same crash as me with zig-window?
<marler8997> haven't built it yet...
<marler8997> going to have to get llvm 11 built first...haven't been zig since release
<marler8997> oh wait
<marler8997> I can download your zig compiler?
<marler8997> it's not custom?
<andrewrk> it's just master branch
<andrewrk> nixos has llvm 11 now, you should be able to build against that in a matter of minutes
<marler8997> lame
<marler8997> actually with my new PC, I can build LLVM/clang in like 5 minutes if I remember right
<marler8997> Your version isn't available for download on the README
<marler8997> does seem to exist
<andrewrk> yeah it hasn't made it through the CI yet
<marler8997> ok will build...let's see how long it takes
<daurnimator> andrewrk: so with the new pie support; to expose it in build.zig, we're going to want a common 'standard' option for it. -Dpie=true
<daurnimator> which is similar to a different question I was going to ask: .standardTargetOptions doesn't currently allow the user to specify cpu features.
<daurnimator> I think there's going to be several build options we should expose by default
<daurnimator> What would you think of a `.standardBuildOptions(.{})` ?
a92 has joined #zig
<marler8997> compiling llvm...
<andrewrk> marler8997, nixos doesn't have it already built?
<andrewrk> daurnimator, sounds like a reasonable proposal
<marler8997> it probably does, but I'm not sure I know how to use it correctly
<andrewrk> it's automatic for me
<marler8997> oh?
<marler8997> meh, I like to be able to change the llvm source if I need to
<andrewrk> yeah I just do `nix-shell -p llvm_11` and it's there in 3 seconds
<marler8997> ah
<marler8997> I suppose I can try that at the same time
<daurnimator> andrewrk: k; will make a proposal now so it doesn't get lost
<andrewrk> marler8997, nix-shell -p llvmPackages_11.clang-unwrapped -p llvm_11 -p lld_11
<marler8997> I'm on 20.03...don't think it has 11
<andrewrk> ah
<marler8997> 6 minutes to build llvm...I thought it was faster :(
<marler8997> need to upgrade to new ryzen 9 5950x
<marler8997> lld is 27 seconds
<andrewrk> 6 min for llvm is pretty fast
<marler8997> gotta go fast!
<marler8997> have you timed yours?
<marler8997> clang 3m41s
<marler8997> zig 7 seconds
<marler8997> oh no!
<marler8997> error...yeah that didn't sound right :)
<andrewrk> I was going to say, including generating zig1.o?
msingle has joined #zig
<hlolli__> On top of the head, does someone have know of an example where readline/readline.h is used with zig, I keep getting *** stack smashing detected ***: terminated, I feel like it could be million things at this stage.
<marler8997> oh wow, actually got a compile error: zig_clang_cc1as_main.cpp:521
<andrewrk> hm that probably means nixos patched llvm or clang
<marler8997> I think it's because I'm on gcc 9.2..too old
<andrewrk> that file is a patched clang source file
<marler8997> fixed that one, just initialized Value, now getting an aliasing error in Attr.h:262
<hlolli__> I don't think it takes 3 seconds to enter a llvm shell in nix if it's the first time, the nice thing about nix is the nix store. I bet if you run nix-shell the second time marler8997, it will be 3 seconds or less
<hlolli__> ah nevermind, building it from sources 6 mins.. it takes me 30 minutes on nix. 5 minutes if cached.
<andrewrk> it took 3 seconds for me because it only had to download 1 thing and I have a fast connection
<marler8997> hmmm...getting more uninitialized errors, might need to use a different compiler
<andrewrk> you could use zig-bootstrap
<marler8997> I think fastest path to solution is to update nixos
<hlolli__> I would be interested to know if zig compiles under a wasi32 stdenv host
<marler8997> and use llvm nixos package
<g-w1> hlolli__ iirc someone compiled stage2 to webassembly, but i can't remember who/what repo
<companion_cube> pixelherodev: well, does cproc have as good runtime instrumentation as clang?!
<marler8997> hlolli__, first time running that nix-shell command, only took a few seconds
<hlolli__> nice, in nix you would theoretically be able to rewrite the root environment and compile absolutely everything with different architecture, pretty useless, but in theory, compile clang in wasm then have clang compile zig, but since clang cross compiles, it's quite nonesensical challenge. Although I do remember seeing clang in wasm.
<hlolli__> correct, it was here https://tbfleming.github.io/cib/ but I wish I had the time to know this magic tricks
xentec has quit [Quit: memento mori]
xentec has joined #zig
<marler8997> nix-shell is adding the old version of gcc (9.2)...why
<andrewrk> 9.2 works fine
<marler8997> oh it should?
<marler8997> r u sure?
<andrewrk> pretty sure I was testing with 9.2 for some period of time
<marler8997> I get 34 errors about using uninitialized variables in zig source code
<andrewrk> are they legit?
<andrewrk> if they are false positives we should put a flag to disable that warning
msingle has quit [Ping timeout: 264 seconds]
<andrewrk> add -Wno-maybe-uninitialized
<marler8997> that's what I was looking for :)
<marler8997> and...we're built
<g-w1> out of curiosity, what cpu do you have?
<marler8997> AMD Ryzen 9 3900X 12-Core Processor
hlolli__ has quit [Ping timeout: 256 seconds]
<marler8997> fast NVME is also crucial for fast builds like this
<g-w1> zig uses temporary files?
<marler8997> it uses normal files :)
<marler8997> so @extern returns whether a symbol has been populated?
<marler8997> wow NativeTargetInfo is working
<andrewrk> @extern is a tool for powerful control over external symbols. the thing that makes it determine whether a symbol is populated is using Weak as the GlobalLinkage
gert_ has joined #zig
<marler8997> yeah this is weird, ld is segfaulting
<marler8997> can simplify, just call loader directly
<marler8997> still segfault
<marler8997> so...ld is saying that static-window is statically linked
<andrewrk> yes that is correct
<marler8997> so...the only reason you're actually calling the loader is to get access to the dlopen/dlsym functions
<marler8997> but you're not using it to load any .so files from your dynamic section
<andrewrk> correct
<marler8997> thinking out loud :)
<marler8997> I have a working example that does this, and now a non-working example. I can look at the differences between the 2 but my guess is that ld won't run a static ELF binary
<marler8997> at least, something that it *thinks* is static
<marler8997> ok we can rule out the ".interp" section, my working example doesn't have one
<marler8997> what if we tried linking to a dummy so file?
<marler8997> trick the loader
<marler8997> ok, when I link to an so...ld no longer says it's a static executable
<marler8997> but we still get a segfault
xackus has quit [Ping timeout: 260 seconds]
<marler8997> it's pie
<marler8997> pie is not working
<marler8997> you can replace main with an empty body, compile it and try to run it with the loader and it will segfault
<marler8997> so...first, trick the loader by linking to a dummy so file
<marler8997> and comment out static_window_exe.pie = true
<marler8997> now loader can load/run the exe
<marler8997> when I fix that...we get a setgfault somewhere in NativeTargetInfo (probably the segfault I was seeing)
msingle has joined #zig
a92 has quit [Quit: My presence will now cease]
msingle has quit [Ping timeout: 240 seconds]
msingle has joined #zig
<andrewrk> marler8997, interesting, so the weak extern is not working
<marler8997> weak extern not working?
<marler8997> it's working to detect whether we are loaded by ld
<marler8997> oh wait
<marler8997> no it's now
<marler8997> no its not
<marler8997> you're right
<marler8997> even more interesting....NativeTargetInfo works when we run statically, but not on the second invocation
<marler8997> these are the 2 problem I worked around by 1. hardcoding the loader (not calling NativeTargetInfo.detect) and 2. using the environment variable
<andrewrk> that doesn't solve the problem though - we need dlopen
<marler8997> dlopen might work
<marler8997> the dynamic section worked in my example
<andrewrk> how wolud we call dlopen?
<marler8997> my guess is it's the @extern implementation, but I can see if I can make that work in C to confirm
<andrewrk> marler8997, just tested. void * __attribute__((weak)) dlopen(const char *filename, int flags); gives the same NULL value
<marler8997> why wouldn't ld be populating dlopen...
<andrewrk> maybe because libdl.so is not mentioned in the dynamic section
<marler8997> yeah that could be
<marler8997> ok, so that fixes the issue
<marler8997> but
<marler8997> now the ELF interpreter is set
<andrewrk> not sure I follow
<marler8997> is I add "linkSystemLibrary("dl")"...now dlopen get populated
<marler8997> but now static-window has an ELF interpreter set, so when the kernel loads it, it doesn't jump to static-window, it goes directly to the loader
<andrewrk> if you linkSystemLibrary("dl") that's the same as doing linkLibC()
<marler8997> is there a way to add "dl" to the dynamic section without adding an ELF interpreter?
<marler8997> maybe patchelf --add-needed
<marler8997> that did it
<marler8997> nice
<marler8997> dlopen gettting populated after this: patchelf add-needed libdl.so.2 zig-cache/bin/static-window
<andrewrk> oh snap
<marler8997> *--add-needed (not add-needed)
<marler8997> love patchelf
<marler8997> coincidentally, created by the nixos guys
<andrewrk> yep
<marler8997> got further, but still a segfault
<andrewrk> ooh try remove needed on the dummy too
<marler8997> removing libdummy.so works as well
<andrewrk> ok now we both get this right? https://clbin.com/wtLUf
<marler8997> yeah
<andrewrk> oh I know why that is happening
<marler8997> setgfult in extension.append("VK_KHR_surface")....hmmm
<andrewrk> look at libc_bits.h
<andrewrk> I made this file, it's all the libc surface that Vulkan-Loader depends on, and I made everything weak. that means the addrs are NULL if the libc functions don't get loaded. just like dlopen
<andrewrk> so we would need --add-needed for the other libc libs too
<marler8997> ah
<marler8997> simple
<andrewrk> so the extern weak stuff only works for things you have in the dynamic section
<andrewrk> basically we want -lc but then delete the interp section
<marler8997> ah
<marler8997> I haven't found a way to delete interp section
<marler8997> but it looks like we can add "needed" after the fact
<andrewrk> yeah
<marler8997> these are all the "needed" when I linked "dl": libdummy.so.0 libc.so.6 libm.so.6 libpthread.so.0 libdl.so.2 librt.so.1 ld-linux-x86-64.so.2 libutil.so.1
<andrewrk> hmm it didn't work for me even after adding all these needed
<marler8997> yeah me neither
<andrewrk> I wish I could tell where it was hitting the 0x0 segfault. the debugger doesn't tell me
<marler8997> it's in arraylist
<marler8997> it's a weird place
<andrewrk> how did you find that?
<marler8997> printf debugging
<andrewrk> oh
<andrewrk> wait you might be looking at the segfault handler code failing
<andrewrk> the first segfault is the thing we care about
<marler8997> try extensions.append("VK_KHR_surface");
<marler8997> add printf before/after that line
<andrewrk> gah this is exciting but I gotta go
<marler8997> lame
<daurnimator> IIRC when compile C pie code you usually need `-Wl,--as-needed`
<marler8997> we disabled pie
<marler8997> but maybe if we add that option we can re-enable pie...still not sure whether pie is needed
<andrewrk> there's also -fPIC (foo.force_pic = true)
<marler8997> failing in allocator.reallocAtLeast in ArrayList.ensureCapacity...still narrowing down
<andrewrk> marler8997, came back to share this idea really quick: we could maybe avoid the --as-needed thing by setting LD_PRELOAD before execve
<marler8997> yeah might work
<marler8997> yeah that works as well
<andrewrk> that's better because it means we can detect the libc paths at runtime instead of having to put them in the ELF
<marler8997> oh yeah, more flexible
<marler8997> got to go for a bit, I"ll see if I can narrow down the next seg fault later
ur5us_ has quit [Ping timeout: 260 seconds]
<daurnimator> hang on, I need to remember what you guys were doing.... isn't the only path you need the one to the dynamic linker? i.e. /lib/ld-linux*
<marler8997> there's too many variations to know for sure what we need or don't need at this point
<marler8997> we would only need to know the actual file paths to .so files if we can't leverage the .so file lookup semantics of linux loaders
<marler8997> ok, there's something wrong with GeneralPurposeAllocator, it's segfaulting in its alloc function
<daurnimator> marler8997: `strings /lib/ld-linux-x86-64.so.2 | grep libc.so` its in there somewhere :)
<daurnimator> andrewrk: btw no need to set `LD_PRELOAD` yourself (infact that would be dangerous because it'll be inherited); you can use `--preload` to the dynamic linker
<marler8997> daurnimator, ah yes that's better
<marler8997> daurnimator, here's the PR with your suggestion: https://github.com/andrewrk/zig-window/pull/4
<daurnimator> is it always libdl.so.2?
<marler8997> probably not
marnix has joined #zig
marnix has quit [Read error: Connection reset by peer]
<marler8997> after PoC, we can insert logic to try to detect which one to use if we need to
marnix has joined #zig
<marler8997> andrewrk, by the way, you can get gdb to load the symbols by reloading the binary file
<marler8997> (gdb) file ./zig-cache-bin/static-window
<marler8997> gdb is just confused because it detects that you are running "ld", so it stops trying to use the symbols from "static-window"
KIMI_7996__88 has joined #zig
<KIMI_7996__88> how to initialize sentinel array with just \0 ?
<KIMI_7996__88> font_file: [256:0]u8 = '\0',
<KIMI_7996__88> this not work
<KIMI_7996__88> i'm having trouble with array vs in C
<marler8997> var font_file = [_]u8 {0};
<KIMI_7996__88> i don't think my 1st message was sent, i try again: "hi, is type inference in struct member planned? also i have nother question:"
<KIMI_7996__88> marler8997 ty
<marler8997> var font_file : [256]u8 = undefined;
<marler8997> font_file[0] = 0;
<marler8997> that's probably what you are wanting
<KIMI_7996__88> error: expected type '[256:0]u8', found '[1]u8'
<KIMI_7996__88> cannot i do that in struct directly?
<marler8997> if you did it in one statement, you would have to initialize the entire array to 0's
<marler8997> which I'm guessing you don't want
<KIMI_7996__88> i want fill path after i create struct
<KIMI_7996__88> but it complain if i do not
<KIMI_7996__88> not possible to have array initialized with just 1 element?
<marler8997> not sure what you're trying to do, but can you leave out the initialized value?
<marler8997> font_file: [256]u8,
kristoff_it has joined #zig
<KIMI_7996__88> in C i just do similar and i assign jsut with '\0'
<marler8997> C doesn't support struct types with default initializers at all
<KIMI_7996__88> yes, but it can in ZIG
<KIMI_7996__88> i wanted clean the code so put that directly on struct in the ZIG one
<marler8997> I'm not sure what you're trying to do so I'm not sure how to help
<KIMI_7996__88> sorry i'm not very good
<marler8997> I don't have enough context
<marler8997> but what you're doing looks very odd
<KIMI_7996__88> i am trying to create struct, it is font data, i fill it as i load file
msingle has quit [Ping timeout: 265 seconds]
<pfg_> do you know how big the font data is?
<marler8997> first thing I see, there is a MAX_FILE constant (rather than 256)
<marler8997> second thing, why does it need to be sentinel?
<marler8997> third thing, why do you need a default initializer?
<KIMI_7996__88> it is a string null terminated, i need 0 default because i prefer create struct first then i fill data, but right now i can't do that, i don't know how to explain
<pfg_> do you know the max length of the string?
<KIMI_7996__88> pfg_ i don't know the font data size, but here is to store the path
<KIMI_7996__88> i don't know the length, but i don't want to allocate on heap
<KIMI_7996__88> with allocator
<KIMI_7996__88> this is why i want default with 0
<pfg_> ok so allocator.allocZ(u8, length); I think to make a null terminated string
<marler8997> he doesn't want heap
<KIMI_7996__88> i don't need allocator, just this struct
<pfg_> oh you don't want it on heap
<pfg_> you need to know the maximum allowed length for it to be on the stack
<marler8997> I'm actually not sure what [256:0]u8 means...does that mean it's a 257 byte array with a 0 at the end? or that it's guaranteed to have a 0 somewhere inside it?
<pfg_> yes
<pfg_> first one
<marler8997> oh thanks pfg
<marler8997> then KIMI, [256:0] is not what you're wanting
<KIMI_7996__88> what i need?
<marler8997> font_path_buffer: [256]u8,
<pfg_> so probably you could have `path: [256]u8, length: usize` and a `fn pathSlice(v: *V) [:0]u8 {return v.path[0..v.length] }`
<marler8997> Something like this: pub fn font_file(self: @This) [*:0]u8 { return self.font_path_bufer; } (TODO: insert appropriate cast)
<marler8997> yeah pfg_ example is better
<KIMI_7996__88> hmm this is complex :/
<pfg_> slices are easier to work with but they require heap allocation or a consistent memory location unfortunately
<marler8997> yes, what you're doing is a bit odd/complex
earnestly has quit [Ping timeout: 256 seconds]
<marler8997> his memory is not going to be "consistent" whether or not he uses a slice, that's what he signed up for by avoiding the heap
<marler8997> I have a feeling your API is making this overly complex...probably should look at that
<KIMI_7996__88> i'm new i am still trying to learn
<KIMI_7996__88> but i am also not very good at programming
<KIMI_7996__88> i need to rethink this struct
<marler8997> yeah that's fine
<marler8997> How are you using this struct? Do you have code to share?
aerona has quit [Quit: Leaving]
<KIMI_7996__88> i am not using it yet, i just plan how i will load the file and parse data on this struct
cole-h has quit [Ping timeout: 256 seconds]
<KIMI_7996__88> char font_file[256] = { '\0' }; this is in C, but i want store that on the struct
<KIMI_7996__88> someone said &[_]u8 {0}, but then it says it is 1 length array thing, that is why i don't know then
<KIMI_7996__88> i want to do that exactly, but with the type [256]u8
<marler8997> why are you wasting cycles zeroing out that entire array?
<KIMI_7996__88> not entire, just 1st
<KIMI_7996__88> because 1st time string is always empty
<KIMI_7996__88> not undefined
<marler8997> I believe th C syntax you sent zeros out the entire array
<KIMI_7996__88> oh
<KIMI_7996__88> how to zero entire array in ZIG?
<KIMI_7996__88> so i can do the same thing, maybe this is what i don't understand, fill and not just the 1st
<marler8997> I'm not sure that's what you want to do though
<KIMI_7996__88> but i think the best is just the 1st to 0, it is faster as you say
<marler8997> why do you want to set the first one to 0?
<marler8997> why do you want to set any of it to 0?
<KIMI_7996__88> so it is not undefined
<marler8997> why do you not want it to be undefined?
<marler8997> undefined means, don't initialize it yet, I'll initialize it later
<marler8997> which sounds like what you want
<KIMI_7996__88> i don't want, i want it to be empty
<KIMI_7996__88> yes
<marler8997> so you want undefined
<marler8997> what was the "yes" to?
<KIMI_7996__88> but for being safe i want to make it empty on the struct
<KIMI_7996__88> so i don't forget later
<marler8997> undefined doesn't necessarily mean you aren't being safe
<marler8997> it means, I'll initialize this later
<marler8997> you can still have safe code that uses undefined
<KIMI_7996__88> but i can't check if undefined
<KIMI_7996__88> that is why i want it empty
<KIMI_7996__88> because otherwise i can't create struct
<marler8997> why do you want to check if it is empty?
<marler8997> need more context
<marler8997> do you have code to share?
<KIMI_7996__88> before i load font
<KIMI_7996__88> it is just struct right now i plan the code
<KIMI_7996__88> i have nothing written other than struct
<marler8997> you said you need to be able to check if it is empty...if you don't have any code, you do you know you'll need to be able to do that?
<KIMI_7996__88> for that fonts http://www.angelcode.com/products/bmfont/
<KIMI_7996__88> but struct don't matter now
<KIMI_7996__88> i don't understand about the initialize array with just 1
<KIMI_7996__88> element
<KIMI_7996__88> i want make sure it is empty
<KIMI_7996__88> before i can use it
gert_ has quit [Quit: WeeChat 2.9]
<marler8997> andrewrk, I'm at a stopping point for the night on this, I got debug stack traces to work (see previous comment), but, something weird is going on that seems to be causing a segfault when returning from certain functions, seemingly to do with allocation, see this pastebin for a small code snippet to reproduce the error: https://pastebin.com/ruWHYGag
<marler8997> KIMI, I don't think you can initialize an array with just one element
<marler8997> that's like trying to initialize 1 byte of a u32 value
<andrewrk> marler8997, what's the connection with that second part?
<marler8997> second part?
<andrewrk> oops I got confused, never mind
<marler8997> pastbin has extra lines for context on where I put it in the code
<marler8997> I believe you can also reproduce the segfault by calling std.heap.PageAllocator.alloc directly
<KIMI_7996__88> https://paste.mozilla.org/tzLLkVF6 something like that
<andrewrk> thanks for the debugging tip
<marler8997> I made it public, and added logging, it works and I print a message before returning, but I never execute any code after calling it
<marler8997> KIMI, I think you could get it to work if you initialized the whole thing to 0, but I don't think there's a way to just initialize one value, again, that's like trying to initialize 1 byte of a u32 value
<marler8997> but I don't think this is the struct you want in the first place, so I wouldn't spend any time on that
<KIMI_7996__88> i think you are right but i am afraid i will use undefined memory after
<marler8997> I don't know what you're trying to do, write a font library? but I would start writing some functions and designing your API
<andrewrk> marler8997, I disassembled it: => 0x000000000028a76d <+445>:vmovdqa XMMWORD PTR [rbp-0xa0],xmm0
<andrewrk> that's on a vector load instruction
<andrewrk> it hints that our stack is not properly aligned
<marler8997> aha!
<andrewrk> got it thanks to your debugging tip
<andrewrk> this has been an amazing collaboration
<marler8997> shared knowledge
<marler8997> freagin stack alignment...
waleee-cl has quit [Quit: Connection closed for inactivity]
decentpenguin has quit [Read error: Connection reset by peer]
<andrewrk> yep, rbp is 0x7fffffff8968 which is not 16 bytes aligned like it needs to be for SIMD
<andrewrk> ok so why isn't the stack aligned
<marler8997> there are compiler options for that
<marler8997> trying to remember
<andrewrk> but doesn't glibc align the stack before calling main?
<marler8997> we aren't using glibc
decentpenguin has joined #zig
<andrewrk> hmmmmm
<marler8997> I'm a bit fuzzy on this, but alignment might be a per function thing as well
<andrewrk> ok I threw in a @setAlignStack(16) in the top of main() and now the segfault is further along!
<marler8997> woohoo
<marler8997> got to VulkanExtensionNotPresent
<andrewrk> hmm interesting we are getting different results then
<andrewrk> I pushed a commit btw
<marler8997> I'm using PageAllocator
<marler8997> when I switch back to GPA, I don't get that far
<andrewrk> hmmm
<andrewrk> btw VulkanExtensionNotPresent is what I got when I used linkLibC() but set the target to native-native-musl
<marler8997> just fyi, with master gpa is getting me to VulkanExtensionNotPresent
<andrewrk> hmm I think we're getting different results
<andrewrk> with the commit I just pushed, I get to here: https://clbin.com/Zmks7
<andrewrk> the next problem I see is that it is calling dlopen@@GLIBC_2.2.5 which is a really old version of glibc
<andrewrk> we would want it to call a newer dlopen version
<marler8997> I bet you're getting farther, I'm running on my headless machine, might need to go to virtualbox which has a display
<andrewrk> that makes sense
sord937 has joined #zig
<andrewrk> you might be getting the correct error based on your setup!
<marler8997> right that's what I'm thinking
<marler8997> but no good error message :(
<marler8997> frame #14, libPath address is 0x2d1?
<andrewrk> oh nice catch
<andrewrk> what is the @entry thing?
<marler8997> good question
<andrewrk> if that means the value when the function is called, that looks correct
<andrewrk> so my hypothesis might be correct, this old version of glibc has a bug and corrupted that parameter
<andrewrk> do you know how to specify a function in C with the glibc version suffix thing?
<marler8997> oh geeze
<marler8997> The only mechanism I've used is a complex linker script
<andrewrk> I think we want to make dlopen a static inline function that tries dlopen@GLIBC_new and if that is NULL then falls back to dlopen@GLIBC_old
<andrewrk> if that makes sense
<andrewrk> there are sooo many puzzle pieces to this problem
<marler8997> yeah, definitely a challenge
<andrewrk> anyway you were trying to go to bed :)
<marler8997> I got a few more minutes in me :)
<marler8997> that's a linker script I put together to wrap the libefivar so file a while back
<marler8997> but hopefully there is an easier way ?
<andrewrk> I think we should be able to use an attribute or inline asm
<andrewrk> good night
<marler8997> night
_whitelogger has joined #zig
ur5us_ has joined #zig
lltt has joined #zig
neptunepunk has joined #zig
sord937 has quit [Ping timeout: 240 seconds]
sord937 has joined #zig
earnestly has joined #zig
ur5us_ has quit [Ping timeout: 264 seconds]
osa1 has quit [Quit: osa1]
osa1 has joined #zig
hnOsmium0001 has quit [Quit: Connection closed for inactivity]
Ichorio has joined #zig
Ichorio has quit [Client Quit]
omglasers2 has joined #zig
osa1 has quit [Quit: osa1]
osa1 has joined #zig
marnix has quit [Ping timeout: 240 seconds]
hlolli__ has joined #zig
supercoven has joined #zig
supercoven has quit [Max SendQ exceeded]
supercoven has joined #zig
supercoven has quit [Max SendQ exceeded]
supercoven has joined #zig
supercoven has quit [Max SendQ exceeded]
supercoven has joined #zig
supercoven has quit [Max SendQ exceeded]
supercoven has joined #zig
supercoven has quit [Max SendQ exceeded]
tme5 has joined #zig
lucid_0x80 has joined #zig
bryanhonof has joined #zig
<bryanhonof> Hello! I have been "investigating" zig for a while now, and I noticed a lot of examples user the ```test "" {}``` syntax to demonstrate the subject. My quest is: can this construct be seen, or used, as an unit test?
<dutchie> yes
<mq32> bryanhonof: in fact, it is *meant* to be a unit test :)
<ifreund> bryanhonof: indeed, running zig test foo.zig will run all `test "foo" {}` blocks
<dutchie> well, you'd normally give the test a better name than ""
<ifreund> you can also add a test step to your build.zig
<mq32> test "my test name" { // test your stuff here }
<dutchie> you can then run a subset of tests by passing some option to `zig test`
<bryanhonof> freund: Oh cool, didn't know that. utchie: Normally I would :P
<bryanhonof> Okay cool, I'll have to go play with it myself. Thanks for the fast response!
* dutchie wonders where the first letters of our nicks went
<bryanhonof> dutchie: Well, you see, I have my emacs's erc zoomed in quite a bit, and I didn't notice I cut of the firm 2 columns of characters. I'm sorry :).
<bryanhonof> So, for the record: ifreund: Oh cool, didn't know that. dutchie: Normally I would :P
<ifreund> heh :)
marnix has joined #zig
bryanhonof has left #zig ["ERC (IRC client for Emacs 27.1)"]
bfredl has quit [Quit: Bridge terminating on SIGTERM]
Snektron has quit [Quit: Bridge terminating on SIGTERM]
alexnask[m] has quit [Quit: Bridge terminating on SIGTERM]
lroy64[m] has quit [Quit: Bridge terminating on SIGTERM]
novaskell has quit [Quit: Bridge terminating on SIGTERM]
BaroqueLarouche has quit [Quit: Bridge terminating on SIGTERM]
Nypsie[m] has quit [Quit: Bridge terminating on SIGTERM]
aterius has quit [Quit: Bridge terminating on SIGTERM]
srgpqt[m] has quit [Quit: Bridge terminating on SIGTERM]
ifreund_ has quit [Quit: Bridge terminating on SIGTERM]
ugla has quit [Quit: Bridge terminating on SIGTERM]
siraben has quit [Quit: Bridge terminating on SIGTERM]
Sergeeeek[m] has quit [Quit: Bridge terminating on SIGTERM]
fengb has quit [Quit: Bridge terminating on SIGTERM]
sergeeeek[m]1 has quit [Quit: Bridge terminating on SIGTERM]
mmohammadi9812 has quit [Quit: Bridge terminating on SIGTERM]
znowflak3[m] has quit [Quit: Bridge terminating on SIGTERM]
josias has quit [Quit: Bridge terminating on SIGTERM]
mokafolio has quit [Quit: Bye Bye!]
mokafolio has joined #zig
Nypsie[m] has joined #zig
mokafolio has quit [Client Quit]
mokafolio has joined #zig
dtz has joined #zig
aterius has joined #zig
lroy64[m] has joined #zig
mmohammadi9812 has joined #zig
bfredl has joined #zig
srgpqt[m] has joined #zig
ugla has joined #zig
return0e[m] has joined #zig
siraben has joined #zig
ifreund_ has joined #zig
alexnask[m] has joined #zig
Sergeeeek[m] has joined #zig
novaskell has joined #zig
hamoko[m] has joined #zig
sergeeeek[m]1 has joined #zig
Snektron has joined #zig
fengb has joined #zig
znowflak3[m] has joined #zig
midi[P][m] has joined #zig
josias has joined #zig
midi[m]1 has joined #zig
midi[m] has joined #zig
BaroqueLarouche has joined #zig
lucid_0x80 is now known as suskun
cren has joined #zig
<cren> hi. Is there a good example of an up-to-date way to read user input interactively?
<mq32> afaik not really
<daurnimator> from stdin?
<ifreund> usually you just read from stdin until you get a newline
<cren> uh, yes, i think from stdin
<ifreund> readUntilDelimiterAlloc() can do that
<mq32> does only work for cooked input though
<mq32> not perfect and doesn't allow *any* editing on windows
<mq32> so "HeY" BACKSPACE "y" will yield "HeY\by" on windows and "Hey" on linux
<cren> i want to replicate what python does with its input() builtin pretty much
<cren> ifreund: which import is that from?
<ifreund> cren: std.io.Reader
<dutchie> i found just a naïve .read() on stdin worked fine (into a pre-allocated 4k stack buffer)
<dutchie> i dunno about windows though
<dutchie> after perusing termios(3) for a while it seemed Good Enough™
<daurnimator> cren: FYI you'd do: `std.io.getStdIn().reader().readUntilDelimiterAlloc(...)`
dumenci has joined #zig
suskun has quit [Ping timeout: 256 seconds]
neptunepunk has quit [Quit: Bye]
<cren> daurnimator: you are using .outStream(), isn't that deprecated?
<dutchie> yeah, i haven't updated it for 0.7.0 yet
<cren> oops, yeah, pinged the wrong person whose name begins with d :P
marnix has quit [Ping timeout: 240 seconds]
marnix has joined #zig
<hlolli__> strange, that if I add a std.log.err before a while loop I'm able to fix a segmentation fault
sord937 has quit [Ping timeout: 240 seconds]
sord937 has joined #zig
lltt has quit [Ping timeout: 246 seconds]
marnix has quit [Read error: Connection reset by peer]
marnix has joined #zig
frmdstryr has quit [Ping timeout: 272 seconds]
<sjums> are there any functional http(s) libraries for zig? I've found https://github.com/ducdetronquito/http, but it doesn't seem to support HTTPS just yet
<hlolli__> sjmus I've heard about requestz on reddit, I just know it exists
<sjums> That was the library I meant. Got the wrong url as I had a bunch of tabs open :) But it seem like that relies on the http library I posted and all examples are using HTTP.
<sjums> It looks really good though :) Well written code!
<ifreund> there's also hzzp
<ifreund> though I don't think that support https either
<g-w1> i think haze made a curl wrapper that you could use https://github.com/haze/zex
msingle has joined #zig
<sjums> Right! That's not an entirely bad idea, g-w1
<g-w1> for right now, until the ecosystem is mature, it may be the best option
<cren> either I'm reading it wrong or std.io.Reader.readUntilDelimiterAlloc takes an error as an argument, could somebody explain how/why this is to me?
<ifreund> hmm? you pass an allocator, the delimiter (probably '\n') and a max size you want to read
<g-w1> it takes a reader (self), allocator to allocate the memory, delimiter for the end ('\n') and max_size of reading. it returns an error maybe is what you are thinking about
<ifreund> zig doesn't ignore the fact that memory isn't infinite so you need to pass a max_size
frmdstryr has joined #zig
<cren> the signature on the docs looks like this: fn readUntilDelimiterAlloc(self: io.reader.Reader(*io.fixed_buffer_stream.FixedBufferStream([]const u8),io.fixed_buffer_stream.ReadError,io.fixed_buffer_stream.FixedBufferStream([]const u8).read), *Allocator, delimiter: u8, max_size: u64) ![]u8
<dutchie> oof
<ifreund> that's an instantiation for a specific reader type
<ifreund> if you read the source code the first paramter is just `self: Self`
<cren> ohh I parsed the brackets badly
<ifreund> understandable, that massive type is not at all readable
<cren> especially not with the way my screen squashes it across multiple lines
<dutchie> i find more often than not the stdlib source code is more readable than the docs (for now)
<ifreund> really I recommend just ignoring the generated docs and reading the source code until the docgen gets nicer
<cren> hmm yeah i'll try that. i think i used to do that actually
sawzall has joined #zig
tijb has joined #zig
tijb has quit [Remote host closed the connection]
<cren> where's the source for FixedBufferAllocator? I thought it would be in std/heap
<dutchie> lib/std/heap.zig
<cren> ahh thanks
<pixelherodev> companion_cube: i mean, I don't particularly care
HugoDaniel has joined #zig
<companion_cube> I mean, for all I know, cproc is not production ready... Tcc maybe?
<cren> ... uh, and where's the source for std.io.Reader?
<g-w1> lib/std/io/reader.zig
<ifreund> you might want to get zls set up, its goto definition is quite useful for browsing the std
<cren> thanks ifreund, good idea
<cren> and thanks g-w1
<cren> i was distracted by buffered_reader and bit_reader
donniewest has joined #zig
<cren> is the buffer you pass to the init() method of an allocator the memory location from which allocations are made?
sawzall has quit [Read error: Connection reset by peer]
waleee-cl has joined #zig
sawzall has joined #zig
<dutchie> for FixedBufferAllocator yes, other allocators don't have such a buffer in their init
<dutchie> page_allocator takes no args, GeneralPurposeAllocator takes in a config, ArenaAllocator takes a backing allocator
xackus has joined #zig
skuzzymiglet has joined #zig
hnOsmium0001 has joined #zig
dtz has quit [Quit: Idle for 30+ days]
hamoko[m] has quit [Quit: Idle for 30+ days]
midi[m] has quit [Quit: Idle for 30+ days]
midi[m]1 has quit [Quit: Idle for 30+ days]
<pixelherodev> companion_cube: cproc is production ready I think
<pixelherodev> It's not 100% done, but oasislinux uses it for much of the system
<pixelherodev> Not all yet - there's some pieces missing currently
Mat5 has joined #zig
gpanders has quit [Ping timeout: 246 seconds]
cole-h has joined #zig
maringuu has joined #zig
<maringuu> Hello, I'm currently debugging zig code which uses @fieldParentPtr. Does anyone know an easy way (not calculating the address manually) to do what @fieldParentPtr does in gdb?
<Mat5> G'Day everyone. Finally I success in building Zig 0.7.0 with Manjaro linux. The problem was that the Arch packages for clang seem to be compiled in some way (obscure to me) against the Gnu compiler libraries, reusing them instead of the clang own ones. Because of this prior builds failed as the clang specific shared-libraries can not be found. The solution is building clang from source before compiling Zig with following comma
<Mat5> ) native-linux-gnu native. This should also work for Arch linux.
<Mat5> ciao
Mat5 has left #zig [#zig]
<ifreund> Mat5: you don't need to build from source
<ifreund> ugh
<g-w1> use this cmake .. -DZIG_PREFER_CLANG_CPP_DYLIB=true -GNinja
<g-w1> only ninja if u want
<ifreund> ^ arch packages llvm differrently for whatever reason
<g-w1> they build them as .so instead of .a so the compiler has to be dynamically linked to them
<ifreund> why don't they distribute both :/
<ifreund> probably cause they don't split normal/devel packages but are trying to care a little bit about disk space despite that
<mq32> arch doesn't distribute static libraries
<mq32> by design/philosophy
<ifreund> they are useful for development though
<ifreund> void ships them with the -devel versions of packages for example
<g-w1> maringuu check this out for @fieldParentPtr in gdb https://stackoverflow.com/questions/17024695/container-of-macro-in-gdb-python it seems that you can make a macro to make it very easy
<maringuu> g-w1. Thanks! You seem to be better at googleing than I am :D
<ifreund> g-w1: does that rely on C ABI struct layout?
gpanders has joined #zig
<g-w1> hmm it might. since zig uses optimised struct layouts would it be possible to do it in userland, or maybe the compiler could put it in the debuginfo. i can't wait for zig support in gdb
HugoDaniel has quit [Ping timeout: 240 seconds]
Snetry has quit [Ping timeout: 240 seconds]
Snetry has joined #zig
maringuu has quit [Remote host closed the connection]
TheLemonMan has joined #zig
<TheLemonMan> now that master is green again it's time to update the other PRs o/
HugoDaniel has joined #zig
HugoDaniel has quit [Ping timeout: 260 seconds]
HugoDaniel has joined #zig
HugoDaniel has quit [Client Quit]
haliucinas has quit [Remote host closed the connection]
<g-w1> ifreund: actually I don't think it assumes the c abi because gdb can print regular zig structs and that just does some weird casts.
haliucinas has joined #zig
xackus has quit [Ping timeout: 256 seconds]
<ifreund> could be right, I didn't look closely
<TheLemonMan> andrewrk, if you're in for some easy review there's 7109 for you
SimonN has quit [Quit: Leaving]
tme5 has quit [Quit: Leaving]
KIMI_7996__88 has quit [Remote host closed the connection]
LanceThePants has joined #zig
sawzall has quit [Ping timeout: 240 seconds]
skuzzymiglet has quit [Ping timeout: 240 seconds]
sawzall has joined #zig
<karchnu> does zig compiles linux?
LanceThePants has quit [Ping timeout: 272 seconds]
Shuang has joined #zig
<pixelherodev> ...?
<pixelherodev> karchnu: the kernel?
<TheLemonMan> or the movie?
LanceThePants has joined #zig
<pixelherodev> TheLemonMan: as opposed to applications *on* Linux
<pixelherodev> I wasn't sure what the intended grammatical form was
<g-w1> or compiling zig on linux
<TheLemonMan> or the anime?
<fengb> The movie the game
<TheLemonMan> the _official_ game
sawzall has quit [Ping timeout: 272 seconds]
sawzall has joined #zig
LanceThePants has quit [Ping timeout: 240 seconds]
<andrewrk> TheLemonMan, hmm one thing we have to consider, if the user requests a depfile, they may request it in the other format that we don't parse
<andrewrk> in which case we would have to disable it
<TheLemonMan> ...there's more than a single (and undocumented) format? :O
<karchnu> pixelherodev: the kernel.
<fengb> I think phd’s question is... can Zig compile Linux kernel or can Zig compile to a Linux target
<karchnu> I would like to use zig as a C compiler for a toy OS of mine.
<karchnu> And it would be great to only use Zig, and nothing else, to compile everything.
<g-w1> that should definently work. check this out https://github.com/andrewrk/HellOS
<TheLemonMan> https://www.kernel.org/doc/html/latest/kbuild/llvm.html suggests clang is able to build the kernel
<karchnu> TheLemonMan: thanks. I hope it works out-of-the-box with Zig. That would be awesome.
<andrewrk> karchnu, give it a try, I think you will be pleased :)
<marler8997> karchnu, SamTebbs is also writing a kernel in Zig: https://github.com/ZystemOS/pluto
<karchnu> I will… after all the time I spent trying to get clang and gcc to be able to recompile themselves, I really want to drop them.
<karchnu> marler8997: I saw that, and it's awesome, but I want something usable and stable. Pluto is very much R&D. But I read the logs from time to time. :p
<companion_cube> does zig compile to ebpf yet? :p
aerona has joined #zig
<ifreund> ah, I think my refAllDeclsRecursive function has hit an infinite loop
<ifreund> that explains why it was crashing
<ifreund> Maybe I can track which types I've already seen
skuzzymiglet has joined #zig
xackus has joined #zig
nvmd has joined #zig
ur5us_ has joined #zig
dumenci has quit [Ping timeout: 246 seconds]
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
KIMI has joined #zig
<KIMI> hi, yesterday someone told me how to init array with 0, but i don't remember syntax: glyphs: [MAX_GLYPHS]?*Glyph = &[MAX_GLYPHS]?*Glyph{}, it not work
<KIMI> also is possible to enable type inference?
<KIMI> in struct
<mq32> what is Glyph?
<andrewrk> KIMI, try the ** operator: item ** 10
<KIMI> Glyph is struct
<KIMI> andrewrk what do you mean operator?
<KIMI> i don't know how use operator
<andrewrk> [1]?*Glyph{null} ** MAX_GLYPHS
<KIMI> thanks you
<andrewrk> are you sure you want every item to possibly be null?
<KIMI> yes so i can know if character is available
<andrewrk> ok then that syntax should work for you
<KIMI> it is working thanks
gpanders has quit [Ping timeout: 260 seconds]
filpAM has joined #zig
gpanders has joined #zig
<KIMI> i have path: [] const u8, that i pass in function, i want store that string in a struct, how can i achieve this?
<KIMI> oh nevermind it works i just need both to be const u8
<andrewrk> marler8997, I suspect the next problem we are running into is that we didn't run some necessary start code. for example musl or glibc does some stuff before calling main() to set up threading
<andrewrk> let me back up. I think the symbol versioning thing is still relevant, but I also just got a void linux running in a VM which uses musl as the system libc, and that's what I think we are hitting here
<marler8997> oh right, whatever they do in crt0.o
<marler8997> like set envp
<marler8997> execute constructors would be another one I think
<andrewrk> fuck constructors
Shuang has quit [Remote host closed the connection]
<andrewrk> ahem. excuse me :)
<marler8997> lol...why the hostility there?
<justin_smith> I'm dealing with a library right now which won't hand me an instance of a data type without also initialzing communication with an IPC mechanism with real time constraints. So in order to debug my code, I need to make a wrapper around the whole API that allows using an opaque dummy object.
<justin_smith> alternatively I could muck around with lib internal hacks and hope they don't break it on the next release
<justin_smith> I'd call that a problem with constructors
<justin_smith> (third option is hack up a real time debugger of some sort I guess?)
<marler8997> sounds like a problem with the library misusing constructors to me
<justin_smith> marler8997: this is extreme, but it's the kind of thing constructors are often used for, the "invariants" that a lib author has in mind don't always match what I need, especially if I want to make my code testable in isolation
<marler8997> one case I see for them is initialzing multi-threaded synchronization data structrues (like mutexes) in a library
<marler8997> but then again, an explicit function might also work in most cases
<justin_smith> the difference of course is that using a constructor makes some intermediate broken state impossible
radgeRayden has joined #zig
<justin_smith> but I think that in what claims to be low level programming, separating the intantiation from data and the initialization (and documenting the constraints!) is probably apropriate
nvmd has quit [Ping timeout: 272 seconds]
nvmd has joined #zig
sord937 has quit [Quit: sord937]
<ifreund> error: expected type 'fn(?*c_void) callconv(.C) c_int', found 'fn(*View) callconv(.C) c_int'
<ifreund> huh? shouldn't that coerce?
<pixelherodev> ifreund: not as arg in a function type, I think?
<pixelherodev> ?*c_void to *View should, I think.
<ifreund> it's going the other way actually
<pixelherodev> Either way
<pixelherodev> (didn't read it too closely :P)
<ifreund> and similar conversions of functions pointers seem to work in other places
<pixelherodev> Don't know what to tell you
<ifreund> guess I'll just pointer cast :P
<ifreund> probably a stage1 bug, that conversion is safe
<pixelherodev> Or *is* it? (*dun dun dun*)
<pixelherodev> (it totally is though)
<ifreund> I swear this exact same thing works in other places in my codebase though
df[m] has joined #zig
SiwelG has joined #zig
omglasers2 has quit [Read error: Connection reset by peer]
marnix has quit [Remote host closed the connection]
hlolli__ has quit [Ping timeout: 272 seconds]
marnix has joined #zig
nvmd has quit [Ping timeout: 264 seconds]
nvmd has joined #zig
donniewest has quit [Quit: WeeChat 3.0]
SiwelG has quit [Remote host closed the connection]
nvmd has quit [Ping timeout: 264 seconds]
jmiven has quit [Quit: reboot]
jmiven has joined #zig
marnix has quit [Ping timeout: 246 seconds]
<marler8997> I'm thinking of putting together my own baby monitor, first thought I had was to use a raspberry pi, but open to suggestions if anyone has any
<justin_smith> marler8997: it's definitely going to be relatively turn-key on rpi, I wouldn't be surprised if you couldn't just add a copy/paste config to nginx to serve v4l data off some qeury path
<justin_smith> marler8997: if your goal isn't to write code, this blog post seems to describe the config needed to make it work https://www.jungledisk.com/blog/2017/07/03/live-streaming-mpeg-dash-with-raspberry-pi-3/
<justin_smith> if you actually want to write code, I assume gluing gstreamer to some small http lib is possible...
skuzzymiglet has quit [Ping timeout: 272 seconds]
nvmd has joined #zig
msingle has quit [Ping timeout: 260 seconds]
msingle has joined #zig
ur5us_ has quit [Ping timeout: 264 seconds]