Stage2: printf is sometimes converted to putchar or puts in ReleaseMode #12533
Labels
use case
Describes a real use case that is difficult or impossible, but does not propose a solution.
Milestone
Zig Version
0.10.0-dev.3659+e5e6eb983
Steps to Reproduce
test-printf.zig:
Expected Behavior
Expected
printf
to be in the symbol table. Expectedputs
andputchar
to not be in the symbol table.This is the behavior I get by doing one of:
-fstage1
-O Debug
instead of-O ReleaseSmall
Actual Behavior
puts
orputchar
are in the symbol table, andprintf
is not.I experience this with all of
ReleaseSmall
,ReleaseFast
, andReleaseSafe
.This seems to be a fairly standard optimization for C, but it doesn't really make sense to me if libc is not used.
For the most zig programs, I imagine this optimization is fine. This behavior causes issues at link-time if puts or putchar are not defined.
The specific case I have is for compiling an OS (riscv64-freestanding) that defines
printf
but notputs
orputchar
. This is not a big deal to work around, but it was quite confusing to me when I was getting link errors such asLLD Link... ld.lld: error: undefined symbol: puts
andld.lld: error: undefined symbol: putchar
and I had no references toputs
orputchar
in my code.This issue is probably not restricted to
printf
because LibCallSimplifier appears to have optimizations for other functions as well.It is pretty cool that zig/llvm can do these optimizations if you've gone through the effort of implementing the libc functions with compatible functionality. Though it invites a really confusing situation for anybody who implements libc functions with different functionality.
The text was updated successfully, but these errors were encountered: