Bug 5870

Summary: argv and argc not passed to C constructor
Product: uClibc Reporter: Martin Assarsson <martin.assarsson>
Component: Standard ComplianceAssignee: unassigned
Status: NEW ---    
Severity: normal CC: uclibc-cvs
Priority: P5    
Version: 0.9.33   
Target Milestone: ---   
Hardware: Other   
OS: Linux   
Host: Target:
Build:

Description Martin Assarsson 2013-01-15 08:31:16 UTC
When using constructor methods they do not get argv and argc.
Following code extract is working on standard glibc, but gives coredump on uClibc.
Untill fixed I will use /proc/self/cmdline.

Example:
static void program_environment(int argc, char **argv, char **envp) __attribute__ ((constructor (100)));

static void program_environment(int argc, char **argv, char **envp) 
{
	int c;
	static struct option long_options[] = {
		{"help", 0, 0, 'h'},
		{"version", 0, 0, 'v'},
		{0, 0, 0, 0}
	};

	opterr = 0;
	optind = 0;

	while (1)
	{
		int option_index = 0;

		c = getopt_long(argc, argv, arguments, long_options, &option_index);

		if (c == -1) break;

		switch (c) {
		case 'h':
			program_help = true;
			break;
		case 'v':
			program_version = true;
			exit ( 0 );
		default:
			break;
		}
	}
}

int main(int argc, char **argv, char **envp) 
{
	program_help = false;
	while (1)
	{
		sleep(10);
	}
}