https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100005

            Bug ID: 100005
           Summary: undefined reference to `_rdrand64_step'
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thiago at kde dot org
  Target Milestone: ---

$ cat rdrand.c
#include <immintrin.h>

#define NUM_RANDOM_NUMBERS_TO_GENERATE  1024

typedef int (*Generator)(unsigned long long *);

int fill_array(Generator generator, unsigned long long *rand_array)
{
    for (int i = 0; i < NUM_RANDOM_NUMBERS_TO_GENERATE; i++) {
        // fast attempt once:
        if (__builtin_expect(generator(&rand_array[i]), 1))
            continue;

        // retry up to 16 times
        int j;
        for (j = 0; j < 16; ++j) {
            if (generator(&rand_array[i]))
                break;
        }
        if (j == 16) {
            // failed, the RNG is out of entropy
            return -1;
        }
    }

    return 0;
}

int main()
{
    unsigned long long rand_array[NUM_RANDOM_NUMBERS_TO_GENERATE];
    fill_array(_rdrand64_step, rand_array);
}

$ ~/dev/gcc/bin/gcc -march=haswell -O2 rdrand.c 
/usr/bin/ld: /tmp/ccTlQIsV.o: in function `main':
rdrand.c:(.text.startup+0x8): undefined reference to `_rdrand64_step'
collect2: error: ld returned 1 exit status

$ ~/dev/gcc/bin/gcc --version                  
gcc (GCC) 11.0.1 20210325 (experimental)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Happens in C++ too, including passing as a template parameter.

Reply via email to