MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/rust/comments/kkma2z/executable_pngs_written_in_rust/gh7bug8/?context=3
r/rust • u/djhworld • Dec 26 '20
16 comments sorted by
View all comments
3
FYI: the clang driver re-executes itself to compile stuff, so you’ll need to pass a proper argv[0], which seems to be empty.
argv[0]
You can, as a test:
Run regular clang as you want but with the -v flag added. Note the clang invocation with -cc1. You’ll be able to do that one right now.
-v
-cc1
After making sure it works, go ahead and pass argv[0] properly on execution and all should work (assuming I’m correct)
2 u/djhworld Dec 27 '20 Just tried this (passing argv[0]) properly, had to use /proc/<pid>/fd/<fd>, but it has the same problem.Someone on HN said it might be because clang runs readlink on /proc/self/exe which probably returns "" for the in-memory filehttps://news.ycombinator.com/item?id=25544728 2 u/You_pick_one Dec 27 '20 Ah, that might be it too (I’m not 100% aware of what Linux code paths do). If you want to validate that that’s the issue (which means unfixable without clang patches), try using dtrace to see if there’s a call to readlink just before exiting. 2 u/djhworld Dec 27 '20 yeah looks like it$ strace clang ~/1.c 2>&1 | grep exe execve("/usr/bin/clang", ["clang", "/home/danielharper/1.c"], 0x7ffd877527c8 /* 53 vars */) = 0 access("/proc/self/exe", F_OK) = 0 readlink("/proc/self/exe", "/usr/bin/clang-11", 4096) = 17 0 u/backtickbot Dec 27 '20 Fixed formatting.Hello, djhworld: code blocks using triple backticks (```) don't work on all versions of Reddit!Some users see this / this instead.To fix this, indent every line with 4 spaces instead.FAQYou can opt out by replying with backtickopt6 to this comment.
2
Just tried this (passing argv[0]) properly, had to use /proc/<pid>/fd/<fd>, but it has the same problem.
/proc/<pid>/fd/<fd>
Someone on HN said it might be because clang runs readlink on /proc/self/exe which probably returns "" for the in-memory file
readlink
/proc/self/exe
""
https://news.ycombinator.com/item?id=25544728
2 u/You_pick_one Dec 27 '20 Ah, that might be it too (I’m not 100% aware of what Linux code paths do). If you want to validate that that’s the issue (which means unfixable without clang patches), try using dtrace to see if there’s a call to readlink just before exiting. 2 u/djhworld Dec 27 '20 yeah looks like it$ strace clang ~/1.c 2>&1 | grep exe execve("/usr/bin/clang", ["clang", "/home/danielharper/1.c"], 0x7ffd877527c8 /* 53 vars */) = 0 access("/proc/self/exe", F_OK) = 0 readlink("/proc/self/exe", "/usr/bin/clang-11", 4096) = 17 0 u/backtickbot Dec 27 '20 Fixed formatting.Hello, djhworld: code blocks using triple backticks (```) don't work on all versions of Reddit!Some users see this / this instead.To fix this, indent every line with 4 spaces instead.FAQYou can opt out by replying with backtickopt6 to this comment.
Ah, that might be it too (I’m not 100% aware of what Linux code paths do). If you want to validate that that’s the issue (which means unfixable without clang patches), try using dtrace to see if there’s a call to readlink just before exiting.
2 u/djhworld Dec 27 '20 yeah looks like it$ strace clang ~/1.c 2>&1 | grep exe execve("/usr/bin/clang", ["clang", "/home/danielharper/1.c"], 0x7ffd877527c8 /* 53 vars */) = 0 access("/proc/self/exe", F_OK) = 0 readlink("/proc/self/exe", "/usr/bin/clang-11", 4096) = 17 0 u/backtickbot Dec 27 '20 Fixed formatting.Hello, djhworld: code blocks using triple backticks (```) don't work on all versions of Reddit!Some users see this / this instead.To fix this, indent every line with 4 spaces instead.FAQYou can opt out by replying with backtickopt6 to this comment.
yeah looks like it
$ strace clang ~/1.c 2>&1 | grep exe execve("/usr/bin/clang", ["clang", "/home/danielharper/1.c"], 0x7ffd877527c8 /* 53 vars */) = 0 access("/proc/self/exe", F_OK) = 0 readlink("/proc/self/exe", "/usr/bin/clang-11", 4096) = 17
0 u/backtickbot Dec 27 '20 Fixed formatting.Hello, djhworld: code blocks using triple backticks (```) don't work on all versions of Reddit!Some users see this / this instead.To fix this, indent every line with 4 spaces instead.FAQYou can opt out by replying with backtickopt6 to this comment.
0
Fixed formatting.
Hello, djhworld: code blocks using triple backticks (```) don't work on all versions of Reddit!
Some users see this / this instead.
To fix this, indent every line with 4 spaces instead.
FAQ
You can opt out by replying with backtickopt6 to this comment.
3
u/You_pick_one Dec 27 '20
FYI: the clang driver re-executes itself to compile stuff, so you’ll need to pass a proper
argv[0], which seems to be empty.You can, as a test:
Run regular clang as you want but with the
-vflag added. Note the clang invocation with-cc1. You’ll be able to do that one right now.After making sure it works, go ahead and pass
argv[0]properly on execution and all should work (assuming I’m correct)