Undefined reference to `rdtsc'

Hi there,

Compiling haproxy 2.2 w/ TRACE=1 on mac host, inside ubuntu container, using this command,

make -j $(nproc) TARGET=linux-glibc USE_LUA=1 TRACE=1

throws following error:

/usr/bin/ld: src/calltrace.o: in function `make_line':
/opt/src/calltrace.c:204: undefined reference to `rdtsc'
/usr/bin/ld: src/calltrace.o: in function `calltrace':
/opt/src/calltrace.c:277: undefined reference to `rdtsc'
collect2: error: ld returned 1 exit status
make: *** [Makefile:864: haproxy] Error 1

Following fixes the issue (found on SO):

 __inline__ uint64_t rdtsc(void)
uint32_t lo, hi;
__asm__ __volatile__ (
        "xorl %%eax,%%eax \n        cpuid"
        ::: "%rax", "%rbx", "%rcx", "%rdx");
__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
return (uint64_t)hi << 32 | lo;

I don’t understand why it doesn’t work out of the box…surely the patch should not needed. Am I missing something?


haproxy 2.2 is a branch but not a release. I have no idea whether you are using 2.2.0 from July 2020 or 2.2.31 from August 2023.

That being said, the 2.2 release branch is in " critical fixes only" mode, and will be EOLed in a few months.

Haproxy version 2.2.4, released in September 2020 contains a fix for a missing include in the calltrace code, this could be it if you are running code older than that.

Ah great thanks. To by pass this issue i went to the docker repo of haproxy that has nice env to build docker images, updated it to build image w/ TRACE=1 flag set and used the generated image.

Thanks for mentioning that 2.2 will be phasing out soon. We’ll be planning to move out of it hopefully before q4’24.