Bug 5870 - argv and argc not passed to C constructor
Summary: argv and argc not passed to C constructor
Status: NEW
Alias: None
Product: uClibc
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: 0.9.33
Hardware: Other Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-15 08:31 UTC by Martin Assarsson
Modified: 2013-01-15 08:31 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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);
	}
}