Skip to content
New issue

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

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

Already on GitHub? # to your account

Defining _POSIX_C_SOURCE hides asprintf and dlvsym on FreeBSD #169

Closed
lantw44 opened this issue May 1, 2018 · 2 comments
Closed

Defining _POSIX_C_SOURCE hides asprintf and dlvsym on FreeBSD #169

lantw44 opened this issue May 1, 2018 · 2 comments

Comments

@lantw44
Copy link
Contributor

lantw44 commented May 1, 2018

libepoxy currently fails to compile on FreeBSD:

[47/51] Compiling C object 'test/test@@glx_alias_prefer_same_name@exe/dlwrap.c.o'.
FAILED: test/test@@glx_alias_prefer_same_name@exe/dlwrap.c.o 
clang -Itest/test@@glx_alias_prefer_same_name@exe -Itest -I../../source/libepoxy-1.5.1/test -Iinclude -I../../source/libepoxy-1.5.1/include -Isrc -I../../source/libepoxy-1.5.1/src -Iinclude/epoxy -Xclang -fcolor-diagnostics -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=gnu99 -O0 -g -march=corei7 -B/home/lantw44/.local/bin -g3 -O0 -D_THREAD_SAFE -pthread -Wpointer-arith -Wmissing-declarations -Wformat=2 -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wbad-function-cast -Wold-style-definition -Wdeclaration-after-statement -Wunused -Wuninitialized -Wshadow -Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls -Werror=implicit -Werror=nonnull -Werror=init-self -Werror=main -Werror=missing-braces -Werror=sequence-point -Werror=return-type -Werror=trigraphs -Werror=array-bounds -Werror=write-strings -Werror=address -Werror=int-to-pointer-cast -Werror=pointer-to-int-cast -fno-strict-aliasing -Wno-int-conversion -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L  -MD -MQ 'test/test@@glx_alias_prefer_same_name@exe/dlwrap.c.o' -MF 'test/test@@glx_alias_prefer_same_name@exe/dlwrap.c.o.d' -o 'test/test@@glx_alias_prefer_same_name@exe/dlwrap.c.o' -c ../../source/libepoxy-1.5.1/test/dlwrap.c
../../source/libepoxy-1.5.1/test/dlwrap.c:166:9: error: implicit declaration of function 'asprintf' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    if (asprintf(&wrap_name, "override_%s_%s", prefix, name) < 0) {
        ^
../../source/libepoxy-1.5.1/test/dlwrap.c:166:9: warning: this function declaration is not a prototype [-Wstrict-prototypes]
../../source/libepoxy-1.5.1/test/dlwrap.c:250:41: error: implicit declaration of function 'dlvsym' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
            real_dlsym = (fips_dlsym_t) dlvsym(RTLD_NEXT, "dlsym", version[i]);
                                        ^
../../source/libepoxy-1.5.1/test/dlwrap.c:250:41: note: did you mean 'dlsym'?
../../source/libepoxy-1.5.1/test/dlwrap.c:184:1: note: 'dlsym' declared here
dlsym(void *handle, const char *name)
^
../../source/libepoxy-1.5.1/test/dlwrap.c:250:41: warning: this function declaration is not a prototype [-Wstrict-prototypes]
            real_dlsym = (fips_dlsym_t) dlvsym(RTLD_NEXT, "dlsym", version[i]);
                                        ^
../../source/libepoxy-1.5.1/test/dlwrap.c:250:26: error: cast to 'fips_dlsym_t' (aka 'void *(*)(void *, const char *)') from smaller integer type 'int' [-Werror,-Wint-to-pointer-cast]
            real_dlsym = (fips_dlsym_t) dlvsym(RTLD_NEXT, "dlsym", version[i]);
                         ^
../../source/libepoxy-1.5.1/test/dlwrap.c:250:41: warning: cast from function call of type 'int' to non-matching type 'fips_dlsym_t' (aka 'void *(*)(void *, const char *)') [-Wbad-function-cast]
            real_dlsym = (fips_dlsym_t) dlvsym(RTLD_NEXT, "dlsym", version[i]);
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 warnings and 3 errors generated.
ninja: build stopped: subcommand failed.

FreeBSD does support the non-standard asprintf and dlvsym functions. However, test/meson.build defines _POSIX_C_SOURCE, which causes declarations of non-standard functions to be hidden.

The easiest fix I found is to replace

test_cflags = common_cflags + [
  '-D_XOPEN_SOURCE',
  '-D_POSIX_C_SOURCE=200809L',
]

with

test_cflags = common_cflags

so all extensions are kept enabled.

@ebassi
Copy link
Collaborator

ebassi commented May 1, 2018

I'd probably move all -D... out as global project arguments, using add_project_arguments().

@lantw44
Copy link
Contributor Author

lantw44 commented May 1, 2018

Sorry, I don't understand how can it be fixed by using add_project_arguments. The problem here is that we cannot define _XOPEN_SOURCE or _POSIX_C_SOURCE when compiling a source file which uses non-POSIX extensions, so the change I proposed in the description is to remove these two options, not to apply them to more files.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants