janmojzis / tinyssh

TinySSH is small server (less than 100000 words of code)
Creative Commons Zero v1.0 Universal
1.44k stars 79 forks source link

sysdep: Reference the test code from main #74

Closed mixi closed 1 year ago

mixi commented 1 year ago

With lld 14 and no additional LDFLAGS the referenced foo()-function was optimized out, as an executable was compiled with no reference to the function, also removing the undefined references to the tested libc functions.

This caused the sysdep mechanism to misdetect hasutmploginlogout.h-yes.c and sysdep/hasutmplogwtmp.h-yes.c on musl libc as true, while it should be false, which broke the build later on on the real references in tinyssh code.

This can also be reproduced with gcc with CFLAGS=-ffunction-sections and LDFLAGS=-Wl,--gc-sections.

Instead reference them, but do not evaluate them at runtime by making the prequisite argc == 0. This should be safe from being optimized out even with LTO.