2
3
Fork
You've already forked ncsu
0

add option for PIE + update to Zig 0.11.0 #222

Closed
BratishkaErik wants to merge 0 commits from refs/pull/222/head into zig
pull from: refs/pull/222/head
merge into: selfisekai:zig
selfisekai:zig
selfisekai:zig0.16
selfisekai:master
selfisekai:zig-threaded
selfisekai:openat
selfisekai:chdir
selfisekai:clear
selfisekai:compll
BratishkaErik commented 2023年04月09日 18:17:08 +02:00 (Migrated from code.blicky.net)
Copy link

btw state of C backend looks better now, (削除) but I'm unable to actually build generated code... maybe I forgot some import (削除ここまで) upd: well, now it crashes :):

$ /usr/lib64/zig/9999/bin/zig build-exe /home/bratishkaerik/ncdu/src/main.zig /home/bratishkaerik/ncdu/src/ncurses_refs.c -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -I/usr/include/ncursesw -lncursesw -ltinfow -lc --name ncdu -ofmt=c -fno-strip
$ /usr/lib64/zig/9999/bin/zig build-obj /usr/lib64/zig/9999/lib/compiler_rt.zig -fPIC -fno-strip
$ ncdu
 6.8 MiB [#################################] ncdu.c
 1.3 MiB [###### ] compiler_rt.o.o
 1.3 MiB [###### ] compiler_rt.o
$ clang compiler_rt.o.o ncdu.c /home/bratishkaerik/ncdu/src/ncurses_refs.c -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -I/usr/lib64/zig/9999/lib/ -I/usr/include/ncursesw -lncursesw -ltinfow -lm -lpthread -lc -ldl -lrt -lutil
ncdu.c:8503:42: warning: declaration of built-in function 'fopen' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
zig_extern struct struct__IO_FILE__9566 *fopen(char const *, char const *);
# myriad of similar warnings...
$ ./a.out
Segmentation fault at address 0x0
???:?:?: 0x55d0bd90b0f4 in ??? (???)
???:?:?: 0x55d0bd91dd58 in ??? (???)
???:?:?: 0x55d0bd983fde in ??? (???)
???:?:?: 0x55d0bd9841d7 in ??? (???)
???:?:?: 0x55d0bd9841d7 in ??? (???)
???:?:?: 0x55d0bd8ccbfc in ??? (???)
???:?:?: 0x55d0bd8cb851 in ??? (???)
???:?:?: 0x55d0bd8bfa01 in ??? (???)
???:?:?: 0x55d0bd8bd15b in ??? (???)
[1] 17088 IOT instruction ./a.out
$ zig cc compiler_rt.o.o ncdu.c /home/bratishkaerik/ncdu/src/ncurses_refs.c -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -I/usr/lib64/zig/9999/lib/ -I/usr/include/ncursesw -lncursesw -ltinfow -lm -lpthread -lc -ldl -lrt -lutil
ncdu.c:8503:42: warning: declaration of built-in function 'fopen' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
zig_extern struct struct__IO_FILE__9566 *fopen(char const *, char const *);
# myriad of similar warnings...
$ ./a.out
Illegal instruction at address 0x378f21
/home/bratishkaerik/ncdu/ncdu.c:60724:35: 0x378f21 in model_Entry_alloc__anon_11599__11599 (ncdu.c)
 (*t17) = zig_or_u64(zig_and_u64((*t17), UINT64_C(0xfffffffffffffffc)), zig_shl_u64((uint64_t)a0, UINT8_C(0)));
 ^
/home/bratishkaerik/ncdu/ncdu.c:29680:9: 0x33f53b in model_Entry_create__5080 (ncdu.c)
 t1 = model_Entry_alloc__anon_11599__11599(a0, a1, a2);
 ^
/home/bratishkaerik/ncdu/ncdu.c:30069:8: 0x385d26 in scan_ScanDir_addStat__4898 (ncdu.c)
 t16 = model_Entry_create__5080(t0, t28, a1);
 ^
/home/bratishkaerik/ncdu/ncdu.c:19915:9: 0x337368 in scan_Context_addStat__4890 (ncdu.c)
 t18 = scan_ScanDir_addStat__4898(t32, t16, t20);
 ^
/home/bratishkaerik/ncdu/ncdu.c:32226:3: 0x3e88d8 in scan_scanDir__4860 (ncdu.c)
 scan_Context_addStat__4890(t16, a3);
 ^
/home/bratishkaerik/ncdu/ncdu.c:20155:2: 0x2aeddc in scan_scan__4863 (ncdu.c)
 scan_scanDir__4860(t5, t31, t26, t30);
 ^
/home/bratishkaerik/ncdu/ncdu.c:12358:2: 0x2aceec in scan_scanRoot__4861 (ncdu.c)
 scan_scan__4863();
 ^
/home/bratishkaerik/ncdu/ncdu.c:13137:8: 0x29b157 in main_main__168 (ncdu.c)
 t23 = scan_scanRoot__4861(t11, t53);
 ^
/home/bratishkaerik/ncdu/ncdu.c:13469:2: 0x29768f in main (ncdu.c)
 main_main__168();
 ^
[1] 18188 IOT instruction ./a.out
btw state of C backend looks better now, ~~but I'm unable to actually build generated code... maybe I forgot some import~~ upd: well, now it crashes :): ```sh $ /usr/lib64/zig/9999/bin/zig build-exe /home/bratishkaerik/ncdu/src/main.zig /home/bratishkaerik/ncdu/src/ncurses_refs.c -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -I/usr/include/ncursesw -lncursesw -ltinfow -lc --name ncdu -ofmt=c -fno-strip $ /usr/lib64/zig/9999/bin/zig build-obj /usr/lib64/zig/9999/lib/compiler_rt.zig -fPIC -fno-strip $ ncdu 6.8 MiB [#################################] ncdu.c 1.3 MiB [###### ] compiler_rt.o.o 1.3 MiB [###### ] compiler_rt.o $ clang compiler_rt.o.o ncdu.c /home/bratishkaerik/ncdu/src/ncurses_refs.c -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -I/usr/lib64/zig/9999/lib/ -I/usr/include/ncursesw -lncursesw -ltinfow -lm -lpthread -lc -ldl -lrt -lutil ncdu.c:8503:42: warning: declaration of built-in function 'fopen' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header] zig_extern struct struct__IO_FILE__9566 *fopen(char const *, char const *); # myriad of similar warnings... $ ./a.out Segmentation fault at address 0x0 ???:?:?: 0x55d0bd90b0f4 in ??? (???) ???:?:?: 0x55d0bd91dd58 in ??? (???) ???:?:?: 0x55d0bd983fde in ??? (???) ???:?:?: 0x55d0bd9841d7 in ??? (???) ???:?:?: 0x55d0bd9841d7 in ??? (???) ???:?:?: 0x55d0bd8ccbfc in ??? (???) ???:?:?: 0x55d0bd8cb851 in ??? (???) ???:?:?: 0x55d0bd8bfa01 in ??? (???) ???:?:?: 0x55d0bd8bd15b in ??? (???) [1] 17088 IOT instruction ./a.out $ zig cc compiler_rt.o.o ncdu.c /home/bratishkaerik/ncdu/src/ncurses_refs.c -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -I/usr/lib64/zig/9999/lib/ -I/usr/include/ncursesw -lncursesw -ltinfow -lm -lpthread -lc -ldl -lrt -lutil ncdu.c:8503:42: warning: declaration of built-in function 'fopen' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header] zig_extern struct struct__IO_FILE__9566 *fopen(char const *, char const *); # myriad of similar warnings... $ ./a.out Illegal instruction at address 0x378f21 /home/bratishkaerik/ncdu/ncdu.c:60724:35: 0x378f21 in model_Entry_alloc__anon_11599__11599 (ncdu.c) (*t17) = zig_or_u64(zig_and_u64((*t17), UINT64_C(0xfffffffffffffffc)), zig_shl_u64((uint64_t)a0, UINT8_C(0))); ^ /home/bratishkaerik/ncdu/ncdu.c:29680:9: 0x33f53b in model_Entry_create__5080 (ncdu.c) t1 = model_Entry_alloc__anon_11599__11599(a0, a1, a2); ^ /home/bratishkaerik/ncdu/ncdu.c:30069:8: 0x385d26 in scan_ScanDir_addStat__4898 (ncdu.c) t16 = model_Entry_create__5080(t0, t28, a1); ^ /home/bratishkaerik/ncdu/ncdu.c:19915:9: 0x337368 in scan_Context_addStat__4890 (ncdu.c) t18 = scan_ScanDir_addStat__4898(t32, t16, t20); ^ /home/bratishkaerik/ncdu/ncdu.c:32226:3: 0x3e88d8 in scan_scanDir__4860 (ncdu.c) scan_Context_addStat__4890(t16, a3); ^ /home/bratishkaerik/ncdu/ncdu.c:20155:2: 0x2aeddc in scan_scan__4863 (ncdu.c) scan_scanDir__4860(t5, t31, t26, t30); ^ /home/bratishkaerik/ncdu/ncdu.c:12358:2: 0x2aceec in scan_scanRoot__4861 (ncdu.c) scan_scan__4863(); ^ /home/bratishkaerik/ncdu/ncdu.c:13137:8: 0x29b157 in main_main__168 (ncdu.c) t23 = scan_scanRoot__4861(t11, t53); ^ /home/bratishkaerik/ncdu/ncdu.c:13469:2: 0x29768f in main (ncdu.c) main_main__168(); ^ [1] 18188 IOT instruction ./a.out ```
BratishkaErik (Migrated from code.blicky.net) reviewed 2023年04月09日 19:09:57 +02:00
yorhel commented 2023年08月01日 12:46:39 +02:00 (Migrated from code.blicky.net)
Copy link

With Zig 0.11 around the corner, let me finally pick this up. Overall looking good, but some feedback:

build.zig: Scrap the comments; the goal of ncdu's build.zig is not to document how build.zig in general is supposed to work.

ui.zig:545:

for(0..height+1)|_i|{consti:u32=@intCast(_i);

I don't always find for loops with ranges better than while loops. It's doubly bad in this case: the intCast is kind of ugly and you just introduced an off-by-one. The original had i < height.

What is your reason for rewriting the buffer handling in tryReadArgsFile() and spawnShell()?

for(txt[0..animation_pos+1])|t|ui.addch(t);

Looking at that change made me realize that ui.addstr() is much simpler.
EDIT: Never mind, addstr() needs zero-termination.

With Zig 0.11 around the corner, let me finally pick this up. Overall looking good, but some feedback: build.zig: Scrap the comments; the goal of ncdu's build.zig is not to document how build.zig in general is supposed to work. ui.zig:545: ```zig for (0..height + 1) |_i| { const i: u32 = @intCast(_i); ``` I don't always find for loops with ranges better than while loops. It's doubly bad in this case: the intCast is kind of ugly and you just introduced an off-by-one. The original had `i < height`. What is your reason for rewriting the buffer handling in tryReadArgsFile() and spawnShell()? ```zig for (txt[0..animation_pos + 1]) |t| ui.addch(t); ``` Looking at that change made me realize that `ui.addstr()` is much simpler. EDIT: Never mind, addstr() needs zero-termination.
BratishkaErik commented 2023年08月03日 20:22:09 +02:00 (Migrated from code.blicky.net)
Copy link

build.zig: Scrap the comments; the goal of ncdu's build.zig is not to document how build.zig in general is supposed to work.

Ok, will do! (in the morning)

ui.zig:545:

for(0..height+1)|_i|{consti:u32=@intCast(_i);

I don't always find for loops with ranges better than while loops. It's doubly bad in this case: the intCast is kind of ugly and you just introduced an off-by-one. The original had i < height.

Oh crap, thank you for catching this! Would you like me to revert all these while loop replacements or only those that introduces intCast?

What is your reason for rewriting the buffer handling in tryReadArgsFile() and spawnShell()?

Because replaced functions are deprecated https://github.com/ziglang/zig/issues/15528

> build.zig: Scrap the comments; the goal of ncdu's build.zig is not to document how build.zig in general is supposed to work. Ok, will do! (in the morning) > ui.zig:545: > ```zig > for (0..height + 1) |_i| { > const i: u32 = @intCast(_i); > ``` > I don't always find for loops with ranges better than while loops. It's doubly bad in this case: the intCast is kind of ugly and you just introduced an off-by-one. The original had `i < height`. Oh crap, thank you for catching this! Would you like me to revert all these while loop replacements or only those that introduces intCast? > What is your reason for rewriting the buffer handling in tryReadArgsFile() and spawnShell()? Because replaced functions are deprecated https://github.com/ziglang/zig/issues/15528
yorhel commented 2023年08月03日 21:00:42 +02:00 (Migrated from code.blicky.net)
Copy link

Would you like me to revert all these while loop replacements or only those that introduces intCast?

Just the intCast ones, the rest looks fine.

Because replaced functions are deprecated https://github.com/ziglang/zig/issues/15528

Ah pity, somehow using a writer to read a line feels weird, but alright.

> Would you like me to revert all these while loop replacements or only those that introduces intCast? Just the intCast ones, the rest looks fine. > Because replaced functions are deprecated https://github.com/ziglang/zig/issues/15528 Ah pity, somehow using a writer to read a line feels weird, but alright.
yorhel commented 2023年08月04日 12:47:45 +02:00 (Migrated from code.blicky.net)
Copy link

Pulled, thanks! I'll do a bit more testing and then fix a new release.

Pulled, thanks! I'll do a bit more testing and then fix a new release.

Pull request closed

This pull request cannot be reopened because the branch was deleted.
Sign in to join this conversation.
No reviewers
No labels
1.x
2.x
bug
feature
imported
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
selfisekai/ncsu!222
Reference in a new issue
selfisekai/ncsu
No description provided.
Delete branch "refs/pull/222/head"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?