Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 564420 - sys-libs/glibc-2.22-r1: Cannot compile program using *addrinfo struct/functions and -D_POSIX_C_SOURCE=1
Summary: sys-libs/glibc-2.22-r1: Cannot compile program using *addrinfo struct/functio...
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Gentoo Toolchain Maintainers
URL: https://sourceware.org/bugzilla/show_...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-29 14:27 UTC by gentoo-user
Modified: 2015-10-29 16:53 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gentoo-user 2015-10-29 14:27:52 UTC
When trying to compile a (previously working) program against glibc-2.22, I got compilation errors due to getaddrinfo not being found.
When trying to compile a short test program with `gcc -Wall gai.c', gcc outputs numerous errors with regards to getaddrinfo/gai_strerror/freeadrrinfo not being declared and not being able to determine the storage size of the addrinfo struct. The same program compiles on a system with sys-libs/glibc-2.20-r2 and used to compile with sys-libs/glibc-2.21-r1 (haven't tried downgrading glibc yet).
Test Program:
#define _POSIX_C_SOURCE 1
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>

int main()
{
	struct addrinfo hints, *res;
	int ret;

	memset(&hints, 0, sizeof(hints));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_protocol = IPPROTO_TCP;

	if ((ret = getaddrinfo("google.com", "443", &hints, &res)) != 0) {
		const char *err = gai_strerror(ret);
		printf("getaddrinfo: %s\n", err);
		return 1;
	}

	freeaddrinfo(res);

	return 0;
}

Reproducible: Always

Steps to Reproduce:
1. Create/copy test program into gai.c
2. gcc -Wall gai.c
Actual Results:  
Program does not compile.

Expected Results:  
Program compiles normally.
Comment 1 gentoo-user 2015-10-29 14:46:41 UTC
So I tried downgrading glibc, it didn't really work:
glibc-2.22-r1] bash: loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_COLLATE) / sizeof (_nl_value_type_LC_COLLATE[0]))' failed.
 * The ebuild phase 'postrm' has been killed by signal 6.
bash: loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_COLLATE) / sizeof (_nl_value_type_LC_COLLATE[0]))' failed.
Sandboxed process killed by signal: Aborted

Now when I try running most programs I get a loadlocale error:
locale: loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_COLLATE) / sizeof (_nl_value_type_LC_COLLATE[0]))' failed.

I guess it's restore from backup time.
Comment 2 gentoo-user 2015-10-29 15:04:26 UTC
Compiling the test program works with sys-libs/glibc-2.21-r1
Comment 3 Mike Gilbert gentoo-dev 2015-10-29 15:26:11 UTC
Why are you setting _POSIX_C_SOURCE to 1? Your test program compiles sucessfully when that is unset or set to a greater value like 200809L.
Comment 4 gentoo-user 2015-10-29 15:52:11 UTC
I defined _POSIX_C_SOURCE 1 because the original program that had the error uses std=c99 (instead of the default gnu89) and because of getaddrinfo(3):
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
   getaddrinfo(), freeaddrinfo(), gai_strerror():
   _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE

Was this just a case of glibc being out of date with sys-apps/man-pages?
Comment 5 gentoo-user 2015-10-29 16:11:01 UTC
Changing the define for _POSIX_C_SOURCE to 200809L fixes compilation on glibc-2.22.

Should I file a bug against sys-apps/man-pages?
Comment 6 Mike Gilbert gentoo-dev 2015-10-29 16:26:57 UTC
Let's let the toolchain guys weigh in.
Comment 7 SpanKY gentoo-dev 2015-10-29 16:53:47 UTC
the change in question was deliberate -- see upstream report:
https://sourceware.org/bugzilla/show_bug.cgi?id=18529

the man-page is incorrect, but that has been reported already:
http://article.gmane.org/gmane.linux.man/9657/match=getaddrinfo