As John pointed out. I had a piece of code in one of my header files that went like this:
# ifndef __attribute__
# define __attribute__(x)
# endif
Because of it any __attribute__() macro expanded to nothing in header files.
I am still not sure why lack of attributes would cause this linker error but that error only appears for object files, including standard library headers, compiled with the -Ofast optimization flag (maybe some other flags but I haven't checked)