I got the following error when compiling test-open.c with -D_FORTIFY_SOURCE=2.
$ gcc -DHAVE_CONFIG_H -I. -DGNULIB_STRICT_CHECKING=1 -I. -I. -I.. -I./.. -I../gllib -I./../gllib -Wall -O1 -D_FORTIFY_SOURCE=2 -g -MT test-open.o -MD -MP -MF .deps/test-open.Tpo -c -o test-open.o test-open.c In file included from /usr/include/fcntl.h:296:0, from ../gllib/fcntl.h:61, from test-open.c:21: test-open.h: In function 'main': /usr/include/bits/fcntl2.h:41:1: error: inlining failed in call to always_inline 'open': indirect function call with a yet undetermined callee open (const char *__path, int __oflag, ...) ^ It seems that open cannot be directly passed to test_open as a function pointer, since it is marked as always_inline. I'm attaching a patch. Regards, -- Daiki Ueno
>From f0ab4954d777a041c88964ce667a9b01e858b395 Mon Sep 17 00:00:00 2001 From: Daiki Ueno <u...@unixuser.org> Date: Fri, 21 Jun 2013 12:37:20 +0900 Subject: [PATCH] test-open: avoid compilation error with -D_FORTIFY_SOURCE=2 * tests/test-open.c (do_open): New wrapper around the system open. --- ChangeLog | 5 +++++ tests/test-open.c | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5e4f02f..90140fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-06-21 Daiki Ueno <u...@gnu.org> + + test-open: avoid compilation error with -D_FORTIFY_SOURCE=2 + * tests/test-open.c (do_open): New wrapper around the system open. + 2013-06-18 Paul Eggert <egg...@cs.ucla.edu> doc: document extern-inline diff --git a/tests/test-open.c b/tests/test-open.c index f04144f..c21b21c 100644 --- a/tests/test-open.c +++ b/tests/test-open.c @@ -34,8 +34,30 @@ SIGNATURE_CHECK (open, int, (char const *, int, ...)); #include "test-open.h" +/* Wrapper around open to test it with test_open. When + -D_FORTIFY_SOURCE=2, open may be inlined and cannot be passed as a + function pointer. */ +static int +do_open (char const *name, int flags, ...) +{ + if (flags & O_CREAT) + { + mode_t mode = 0; + va_list arg; + va_start (arg, flags); + + /* We have to use PROMOTED_MODE_T instead of mode_t, otherwise GCC 4 + creates crashing code when 'mode_t' is smaller than 'int'. */ + mode = va_arg (arg, PROMOTED_MODE_T); + + va_end (arg); + return open (name, flags, mode); + } + return open (name, flags); +} + int main (void) { - return test_open (open, true); + return test_open (do_open, true); } -- 1.8.2.1