Skip to contentSkip to conversation

Posix timer creation failure

DISCUSSION Cédric Chépied 1 participant 2 messages Apr 16, 2024

lore
Share & tools
lore
#0 lore raw

Hi all,

I'm trying to execute a simple posix timer example (see code below). When I compile it "normally", it works fine but when I add xeno-config generated flags (to add RT tasks later) the create_timer function fails (invalid argument).

Can somebody tell me what I am doing wrong please ?
I'm running it on a 32 bit arm (imx6), could it be the "-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64" options ?

Thanks,

Here is the code :

static unsigned int pass_value_by_pointer = 42;

void Timer_has_expired(union sigval timer_data)

{
	printf("Timer expiration handler function; %d\n",
	       *(int*) timer_data.sival_ptr);
}

int main(void)

{
	struct sigevent timer_signal_event;
	timer_t timer;

	struct itimerspec timer_period;

	printf("Create timer\n");
	timer_signal_event.sigev_notify = SIGEV_THREAD;
	timer_signal_event.sigev_notify_function = Timer_has_expired;
	timer_signal_event.sigev_value.sival_ptr =
	    (void*) &pass_value_by_pointer; // as will this (both in a structure)
	timer_signal_event.sigev_notify_attributes = NULL;
	int ret = timer_create(CLOCK_MONOTONIC, &timer_signal_event, &timer);

	if (ret)
	{
		perror("timer_create");
		exit(EXIT_FAILURE);
	}

	printf("Start timer\n");
	timer_period.it_value.tv_sec = 1; // 1 second timer
	timer_period.it_value.tv_nsec = 0; // no nano-seconds
	timer_period.it_interval.tv_sec = 0; // non-repeating timer
	timer_period.it_interval.tv_nsec = 0;

	timer_settime(timer, 0, &timer_period, NULL);
	sleep(2);

	printf("----------------------------\n");
	printf("Start timer a second time\n");
	timer_settime(timer, 0, &timer_period, NULL);
	sleep(2);

	printf("----------------------------\n");
	printf("Start timer a third time\n");
	timer_settime(timer, 0, &timer_period, NULL);

	printf("Cancel timer\n");
	timer_delete(timer);
	sleep(2);
	printf(
	    "The timer expiration handler function should not have been called\n");

	return EXIT_SUCCESS;
}

Here are compilation flags :

sdk/sysroots/x86_64-fslcsdk-linux/usr/bin/arm-fslc-linux-gnueabi/arm-fslc-linux-gnueabi-gcc -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi --sysroot=sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi -O2 -pipe -g -feliminate-unused-debug-types -Isdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi/usr/include/xenomai/cobalt -Isdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi/usr/include/xenomai -O2 -pipe -g -feliminate-unused-debug-types -fmacro-prefix-map=/workdir/build/tmp/work/cortexa7t2hf-neon-fslc-linux-gnueabi/xenomai/3.2.4-r0=/usr/src/debug/xenomai/3.2.4-r0 -fdebug-prefix-map=/workdir/build/tmp/work/cortexa7t2hf-neon-fslc-linux-gnueabi/xenomai/3.2.4-r0=/usr/src/debug/xenomai/3.2.4-r0 -fdebug-prefix-map=sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi= -fdebug-prefix-map=sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi-native= -D_GNU_SOURCE -D_REENTRANT -fasynchronous-unwind-tables -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 -D__COBALT__ -Isdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi/usr/include/xenomai/alchemy -MD -MT CMakeFiles/timer.dir/timer.c.o -MF CMakeFiles/timer.dir/timer.c.o.d -o CMakeFiles/timer.dir/timer.c.o -c Tests/posixTimer/timer.c

sdk/sysroots/x86_64-fslcsdk-linux/usr/bin/arm-fslc-linux-gnueabi/arm-fslc-linux-gnueabi-gcc -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi --sysroot=sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi -O2 -pipe -g -feliminate-unused-debug-types -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-z,relro,-z,now -Wl,--no-as-needed -Wl,@sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi/usr/lib/modechk.wrappers -lalchemy -lcopperplate sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi/usr/lib/xenomai/bootstrap.o -Wl,--wrap=main -Wl,--dynamic-list=sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi/usr/lib/dynlist.ld -Lsdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi/usr/lib -lcobalt -lmodechk -lpthread -lrt -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -fmacro-prefix-map=/workdir/build/tmp/work/cortexa7t2hf-neon-fslc-linux-gnueabi/xenomai/3.2.4-r0=/usr/src/debug/xenomai/3.2.4-r0 -fdebug-prefix-map=/workdir/build/tmp/work/cortexa7t2hf-neon-fslc-linux-gnueabi/xenomai/3.2.4-r0=/usr/src/debug/xenomai/3.2.4-r0 -fdebug-prefix-map=sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi= -fdebug-prefix-map=sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi-native= -Wl,-z,relro,-z,now -Wl,@sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi/usr/lib/cobalt.wrappers -Wl,@sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi/usr/lib/cobalt-glibc-time64.wrappers CMakeFiles/timer.dir/timer.c.o -o timer

Signature · 4 lines
Cédric Chépied
<[email protected]>

<http://events.drotek.com/>
#1 lore raw
Quoted 8 lines · Cédric Chépied

I'm trying to execute a simple posix timer example (see code below). When I compile it "normally", it works fine but when I add xeno-config generated flags (to add RT tasks later) the create_timer function fails (invalid argument).

Here are compilation flags :

sdk/sysroots/x86_64-fslcsdk-linux/usr/bin/arm-fslc-linux-gnueabi/arm-fslc-linux-gnueabi-gcc -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi --sysroot=sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi -O2 -pipe -g -feliminate-unused-debug-types -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-z,relro,-z,now -Wl,--no-as-needed -Wl,@sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi/usr/lib/modechk.wrappers -lalchemy -lcopperplate sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi/usr/lib/xenomai/bootstrap.o -Wl,--wrap=main -Wl,--dynamic-list=sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi/usr/lib/dynlist.ld -Lsdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi/usr/lib -lcobalt -lmodechk -lpthread -lrt -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -fmacro-prefix-map=/workdir/build/tmp/work/cortexa7t2hf-neon-fslc-linux-gnueabi/xenomai/3.2.4-r0=/usr/src/debug/xenomai/3.2.4-r0 -fdebug-prefix-map=/workdir/build/tmp/work/cortexa7t2hf-neon-fslc-linux-gnueabi/xenomai/3.2.4-r0=/usr/src/debug/xenomai/3.2.4-r0 -fdebug-prefix-map=sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi= -fdebug-prefix-map=sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi-native= -Wl,-z,relro,-z,now -Wl,@sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi/usr/lib/cobalt.wrappers -Wl,@sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi/usr/lib/cobalt-glibc-time64.wrappers CMakeFiles/timer.dir/timer.c.o -o timer

Wrappers seem to be the problem. When I link without "-Wl,@sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi/usr/lib/cobalt.wrappers -Wl,@sdk/sysroots/cortexa7t2hf-neon-fslc-linux-gnueabi/usr/lib/cobalt-glibc-time64.wrappers", timers work. But I won't be able to use the rtcan driver (I won't be able to call ioctl on the socket).

It seems to work by adding "-nostdlib" when linking but then I got "undefined reference to symbol '__aeabi_unwind_cpp_pr0@@GCC_3.5'".
If I disable exceptions with "-fno-exceptions" it compiles and runs fine. But I need C++ exceptions for my "real" code.

What is the correct way to fix this ?

Thanks,

Signature · 4 lines
Cédric Chépied
<[email protected]>

<http://events.drotek.com/>