Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't pin down "implicit declaration" problem #99

Closed
phillipjohnston opened this issue Jan 24, 2022 · 2 comments
Closed

Can't pin down "implicit declaration" problem #99

phillipjohnston opened this issue Jan 24, 2022 · 2 comments

Comments

@phillipjohnston
Copy link

phillipjohnston commented Jan 24, 2022

Working on switching over our libc implementation to use your improved fork, and I'm banging my head against the wall with a problem I don't understand (perhaps because it's the end of the day).

I'm compiling the files with -DPRINTF_ALIAS_STANDARD_FUNCTION_NAMES=1 with clang, but I get the warnings below. GCC also has this problem, although it unhelpfully tells me to include stdio.h, which I am already doing.

I have verified that the header is included, and I'm actually in that logic block that defines printf_ to printf. But the only way I can get these warnings to go away is to actually define int printf(const char* format, ...) ATTR_PRINTF(1, 2);, not printf_.

The other oddity I note is that this only happens for printf calls with only a format string.

printf("Overflow case run.\n");

This one in the same file does not generate the warning:

printf("Running stack overflow test program. Canary value: 0x%p\n", (void*)__stack_chk_guard);

Any thoughts on what I'm missing here?

Clang

[9/12] Compiling C object test/stackprotect_test.p/app_stackcheck_main.c.o
../test/app/stackcheck_main.c:21:2: warning: implicit declaration of function 'printf' is invalid in C99 [-Wimplicit-function-declaration]
        printf("Overflow case run.\n");
        ^
../test/app/stackcheck_main.c:27:2: warning: implicit declaration of function 'printf' is invalid in C99 [-Wimplicit-function-declaration]
        printf("Running stack overflow test program. Canary value: 0x%p\n", __stack_chk_guard);
        ^
2 warnings generated.
[10/12] Compiling C object test/stackp...test.p/.._src_crt_stack_protection.c.o
../src/crt/stack_protection.c:45:2: warning: implicit declaration of function 'printf' is invalid in C99 [-Wimplicit-function-declaration]
        printf("Stack overflow detected! Aborting program.\n");
        ^
1 warning generated.

GCC

[1/2] Compiling C object test/stackprotect_test.p/app_stackcheck_main.c.o
../test/app/stackcheck_main.c: In function 'stack_overflows_here':
../test/app/stackcheck_main.c:21:2: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   21 |  printf("Overflow case run.\n");
      |  ^~~~~~
../test/app/stackcheck_main.c:4:1: note: 'printf' is defined in header '<stdio.h>'; did you forget to '#include <stdio.h>'?
    3 | #include <stdio.h>
  +++ |+#include <stdio.h>
    4 |
@phillipjohnston
Copy link
Author

This also appears to be blocking me on the Arduino library integration. If I invoke printf with an argument:

printf("I'm alive! %d\n", counter++);

I get expected serial output:

15:58:35.970 -> I'm alive! 43
15:58:36.963 -> I'm alive! 44
15:58:37.947 -> I'm alive! 45

However, using only text actually results in no output being generated on the device, although I don't see a compiler warning in the Arduino IDE. But I can confirm the sketch is running with an LED blink. I suspect that call is being optimized out even though I don't see a warning.

printf("I'm alive!\n");

@phillipjohnston
Copy link
Author

BAH. I found the problem: my build system design caused the command-line arg to be missed on some files. That has been corrected. Now to figure out the Arduino issue - but closing this.

kuba2k2 pushed a commit to libretiny-eu/library-printf that referenced this issue Feb 25, 2023
* Added a couple of test cases for exposing the behavior of the `#` modifier (alternative mode) together with `ll` (long long modifier), and specifically exposing the example format string mentioned in bug eyalroz#114.
* Our fix for eyalroz#109 was too eager to keep `FLAG_HASH` - it dropped it only when a precision wasn't specified. We're now going part of the way back - dropping `FLAG_HASH` even when precision wasn't specific - except for octal.
* The `long long` version of ntoa now behaves just like the `long` version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant