Wednesday, November 7, 2012

Autotools, how I hate thee

When writing custom passes for a compiler, it's often a good idea to try running them on real-world programs to assess things like scalability and correctness. Taking a large project and seeing your pass work (and provide useful results!) is an exhilarating feeling. On the other hand, trying to feed in your compiler options into build systems is a good route to an insane asylum.

I complained some time ago about autoconf 2.13 failing because it assumes implicit int. People rightly pointed out that newer versions of autoconf don't assume that anymore. But new versions still come with their own cornucopias of pain. Libtool, for example, believes that the best route to linking a program is to delete every compiler flag from the command line except those it knows about. Even if you explicitly specify them in LDFLAGS. Then there's this conftest program that I found while compiling gawk:

/* Define memcpy to an innocuous variant, in case <limits.h> declares memcpy.
   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
#define memcpy innocuous_memcpy

/* System header to define __stub macros and hopefully few prototypes,
    which can conflict with char memcpy (); below.
    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
    <limits.h> exists even on freestanding compilers.  */

#ifdef __STDC__
# include <limits.h>
#else
# include <assert.h>
#endif
#undef memcpy

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
#ifdef __cplusplus
extern "C"
#endif
char memcpy ();
/* The GNU C library defines this for functions which it implements
    to always fail with ENOSYS.  Some functions are actually named
    something starting with __ and the normal name is an alias.  */
#if defined __stub_memcpy || defined __stub___memcpy
choke me
#endif

int
main ()
{
return memcpy ();
  ;
  return 0;
}

…I think this code speaks for itself in how broken it is as a test. One of the parts of the compiler pass involved asserted due to memcpy not being used in the right way, crashing the compiler. Naturally, this being autoconf, it proceeded to assume that I didn't have a memcpy and thus decided to provide me one, which causes later code to break in spectacular bad function when you realize that memcpy is effectively a #define in modern glibc. And heaven forbid if I should try to compile with -Werror in configure scripts (nearly every test program causes a compiler warning along the lines of "builtin function is horribly misused").

The saddest part of all is that, as bad as autoconf is, it appears to be the least broken configuration system out there…

6 comments:

Anonymous said...

In CMake you set custom C compiler flags like this:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -myflag")

This is then used on all compiles from there on. C++ and linker flags are set similartly.

Unknown said...

Time to write a new set of autotools in python, perhaps?

Jim Rhodes said...

Yeah, sometimes it's hard to use them. You should check some https://paperovernight.com/blog/nursing-capstone-project-ideas nursing capstone project ideas later. I think you will like them.

Bextol said...

Total land area of Andorra is 468 km2 (approx. 181 mi²). 160 km2 of Andorra's territory is covered in forests. and forest land comprises 34% of all the land in the country. http://www.confiduss.com/en/jurisdictions/andorra/environment/

Anonymous said...

Perfectly prepare for school, as well as significantly improve their intellectual abilities. Agree that it is much more interesting for a multiplication online games child to solve examples and study the multiplication table along with colorful and funny characters in the game format.

Maid Service Salt Lake City said...

Great reaading