Skip to contentSkip to conversation

Stubdom GMP build failure for gcc 6

DISCUSSION Wei Liu 4 participants 11 messages Oct 28, 2016 – Oct 29, 2016

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

Hi all

There have been a few reports on stubdom build failure with gcc 6 toolchain. I spent some time yesterday to figure what went wrong. Here is what I found.

When building GMP library, its configure script generates small C programs to determine various aspects of the system. Unfortunately the build rune for it is incorrect, so the test program ends up consuming newlib headers while linking against the host glibc. It's amazing that this even worked in the past few years! :-)

Unfortunately my attempt to fix it by providing LDFLAGS="-nostdlib -LXXX" doesn't work. It turns out that there is no crt generated in newlib. I'm not sure if that's because the newlib port is incomplete or I haven't discovered a way to teach it to generate one.

So what should we do with this? I'm not sure if I can come up with a non-intrusive patch quickly. GMP is only used by tpm emulator, so for the imminent 4.8 release I can write a patch to disable building that.

Ultimately we need to have a proper solution, because there can be other breakages in the future. And I do wish users who need tpm emulator can continue to use it. I don't have a clear answer as to how many people care about this and how can we fix it.

Thoughts?

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#1 lore raw
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 14:10, <[email protected]> wrote:

There have been a few reports on stubdom build failure with gcc 6 toolchain. I spent some time yesterday to figure what went wrong. Here is what I found.

When building GMP library, its configure script generates small C programs to determine various aspects of the system. Unfortunately the build rune for it is incorrect, so the test program ends up consuming newlib headers while linking against the host glibc. It's amazing that this even worked in the past few years! :-)

Quoted 4 lines

Unfortunately my attempt to fix it by providing LDFLAGS="-nostdlib -LXXX" doesn't work. It turns out that there is no crt generated in newlib. I'm not sure if that's because the newlib port is incomplete or I haven't discovered a way to teach it to generate one.

Considering that they can't reasonably try to run any of these test programs (after all this is a cross build), wouldn't it suffice to make up crt*.o just for the configure process, and just providing the necessary symbols to make linking succeed? Agreed this, if anything, makes the present situation even uglier, but it might work.

But what I'm not understanding - what did change with gcc 6 here? There's surely no libc version dependency in the compiler, so whatever worked in older gcc for linking purposes should work here too.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#2 lore raw
Quoted 16 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 14:10, <[email protected]> wrote:

There have been a few reports on stubdom build failure with gcc 6 toolchain. I spent some time yesterday to figure what went wrong. Here is what I found.

When building GMP library, its configure script generates small C programs to determine various aspects of the system. Unfortunately the build rune for it is incorrect, so the test program ends up consuming newlib headers while linking against the host glibc. It's amazing that this even worked in the past few years! :-)

Quoted 4 lines

Unfortunately my attempt to fix it by providing LDFLAGS="-nostdlib -LXXX" doesn't work. It turns out that there is no crt generated in newlib. I'm not sure if that's because the newlib port is incomplete or I haven't discovered a way to teach it to generate one.

Quoted 7 lines

Considering that they can't reasonably try to run any of these test programs (after all this is a cross build), wouldn't it suffice to make up crt*.o just for the configure process, and just providing the necessary symbols to make linking succeed? Agreed this, if anything, makes the present situation even uglier, but it might work.

It might. But that's not sustainable IMO.

One thing is that gmp configure doesn't try to run those test programs, because the configure rune doesn't indicate a cross-build, although it is actually one.

Quoted 5 lines

But what I'm not understanding - what did change with gcc 6 here? There's surely no libc version dependency in the compiler, so whatever worked in older gcc for linking purposes should work here too.

It's not it doesn't link anymore.

A sample test program:

typedef unsigned short ac__type_sizeof_;
static long int longval () { return (long int) (sizeof (ac__type_sizeof_)); }
static unsigned long int ulongval () { return (long int) (sizeof (ac__type_sizeof_)); }
#include <stdio.h>
#include <stdlib.h>
int
main ()
{

FILE *f = fopen ("conftest.val", "w");
if (! f)

    return 1;
  if (((long int) (sizeof (ac__type_sizeof_))) < 0)
    {
      long int i = longval ();
      if (i != ((long int) (sizeof (ac__type_sizeof_))))
	return 1;
      fprintf (f, "%ld\n", i);
    }
  else
    {
      unsigned long int i = ulongval ();
      if (i != ((long int) (sizeof (ac__type_sizeof_))))
	return 1;
      fprintf (f, "%lu\n", i);
    }

return ferror (f) || fclose (f) != 0;
;
return 0;
}

ferror is a macro in newlib, which checks if one certain bit X is set. I suppose the same bit X has a different semantics now in glibc, and then fprintf (a function from glibc) happens to set bit X. This program will then exit with non-zero and configure deems it failed to run.

Wei.

Quoted 2 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 14:50, <[email protected]> wrote:
Quoted 16 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 14:10, <[email protected]> wrote:

There have been a few reports on stubdom build failure with gcc 6 toolchain. I spent some time yesterday to figure what went wrong. Here is what I found.

When building GMP library, its configure script generates small C programs to determine various aspects of the system. Unfortunately the build rune for it is incorrect, so the test program ends up consuming newlib headers while linking against the host glibc. It's amazing that this even worked in the past few years! :-)

Unfortunately my attempt to fix it by providing LDFLAGS="-nostdlib -LXXX" doesn't work. It turns out that there is no crt generated in newlib. I'm not sure if that's because the newlib port is incomplete or I haven't discovered a way to teach it to generate one.

Quoted 8 lines
Quoted 6 lines

Considering that they can't reasonably try to run any of these test programs (after all this is a cross build), wouldn't it suffice to make up crt*.o just for the configure process, and just providing the necessary symbols to make linking succeed? Agreed this, if anything, makes the present situation even uglier, but it might work.

It might. But that's not sustainable IMO.

I agree, and tried to indicate so with the last sentence. It was just a thought for a possible non-intrusive workaround for 4.8.

Quoted 3 lines

One thing is that gmp configure doesn't try to run those test programs, because the configure rune doesn't indicate a cross-build, although it is actually one.

Considering what you write further down, DYM "does try to run" (in which case indeed we're hosed)?

Quoted 43 lines
Quoted 5 lines

But what I'm not understanding - what did change with gcc 6 here? There's surely no libc version dependency in the compiler, so whatever worked in older gcc for linking purposes should work here too.

It's not it doesn't link anymore.

A sample test program:

   typedef unsigned short ac__type_sizeof_;

static long int longval () { return (long int) (sizeof (ac__type_sizeof_)); }
static unsigned long int ulongval () { return (long int) (sizeof (ac__type_sizeof_)); }
#include <stdio.h>
#include <stdlib.h>
int
main ()
{

FILE *f = fopen ("conftest.val", "w");
if (! f)

    return 1;
  if (((long int) (sizeof (ac__type_sizeof_))) < 0)
    {
      long int i = longval ();
      if (i != ((long int) (sizeof (ac__type_sizeof_))))
	return 1;
      fprintf (f, "%ld\n", i);
    }
  else
    {
      unsigned long int i = ulongval ();
      if (i != ((long int) (sizeof (ac__type_sizeof_))))
	return 1;
      fprintf (f, "%lu\n", i);
    }

return ferror (f) || fclose (f) != 0;
;
return 0;
}

Quoted 4 lines

ferror is a macro in newlib, which checks if one certain bit X is set. I suppose the same bit X has a different semantics now in glibc, and then fprintf (a function from glibc) happens to set bit X. This program will then exit with non-zero and configure deems it failed to run.

But how is any of this gcc version dependent?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#4 lore raw
Quoted 30 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 14:50, <[email protected]> wrote:
Quoted 16 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 14:10, <[email protected]> wrote:

There have been a few reports on stubdom build failure with gcc 6 toolchain. I spent some time yesterday to figure what went wrong. Here is what I found.

When building GMP library, its configure script generates small C programs to determine various aspects of the system. Unfortunately the build rune for it is incorrect, so the test program ends up consuming newlib headers while linking against the host glibc. It's amazing that this even worked in the past few years! :-)

Unfortunately my attempt to fix it by providing LDFLAGS="-nostdlib -LXXX" doesn't work. It turns out that there is no crt generated in newlib. I'm not sure if that's because the newlib port is incomplete or I haven't discovered a way to teach it to generate one.

Quoted 8 lines
Quoted 6 lines

Considering that they can't reasonably try to run any of these test programs (after all this is a cross build), wouldn't it suffice to make up crt*.o just for the configure process, and just providing the necessary symbols to make linking succeed? Agreed this, if anything, makes the present situation even uglier, but it might work.

It might. But that's not sustainable IMO.

I agree, and tried to indicate so with the last sentence. It was just a thought for a possible non-intrusive workaround for 4.8.

Quoted 7 lines
Quoted 3 lines

One thing is that gmp configure doesn't try to run those test programs, because the configure rune doesn't indicate a cross-build, although it is actually one.

Considering what you write further down, DYM "does try to run" (in which case indeed we're hosed)?

Yes, I meant "does try to run".

Quoted 43 lines
Quoted 43 lines
Quoted 5 lines

But what I'm not understanding - what did change with gcc 6 here? There's surely no libc version dependency in the compiler, so whatever worked in older gcc for linking purposes should work here too.

It's not it doesn't link anymore.

A sample test program:

   typedef unsigned short ac__type_sizeof_;

static long int longval () { return (long int) (sizeof (ac__type_sizeof_)); }
static unsigned long int ulongval () { return (long int) (sizeof (ac__type_sizeof_)); }
#include <stdio.h>
#include <stdlib.h>
int
main ()
{

FILE *f = fopen ("conftest.val", "w");
if (! f)

    return 1;
  if (((long int) (sizeof (ac__type_sizeof_))) < 0)
    {
      long int i = longval ();
      if (i != ((long int) (sizeof (ac__type_sizeof_))))
	return 1;
      fprintf (f, "%ld\n", i);
    }
  else
    {
      unsigned long int i = ulongval ();
      if (i != ((long int) (sizeof (ac__type_sizeof_))))
	return 1;
      fprintf (f, "%lu\n", i);
    }

return ferror (f) || fclose (f) != 0;
;
return 0;
}

Quoted 7 lines
Quoted 4 lines

ferror is a macro in newlib, which checks if one certain bit X is set. I suppose the same bit X has a different semantics now in glibc, and then fprintf (a function from glibc) happens to set bit X. This program will then exit with non-zero and configure deems it failed to run.

But how is any of this gcc version dependent?

Oh, yes, the subject line is misleading. Sorry.

I wrote that because it was discovered in the context of trying to compile stubdom gmp with gcc 6.

Wei.

Quoted 2 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#5 lore raw
In reply to Wei Liu
Quoted 25 lines · Wei Liu
Quoted 16 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 14:10, <[email protected]> wrote:

There have been a few reports on stubdom build failure with gcc 6 toolchain. I spent some time yesterday to figure what went wrong. Here is what I found.

When building GMP library, its configure script generates small C programs to determine various aspects of the system. Unfortunately the build rune for it is incorrect, so the test program ends up consuming newlib headers while linking against the host glibc. It's amazing that this even worked in the past few years! :-)

Quoted 4 lines

Unfortunately my attempt to fix it by providing LDFLAGS="-nostdlib -LXXX" doesn't work. It turns out that there is no crt generated in newlib. I'm not sure if that's because the newlib port is incomplete or I haven't discovered a way to teach it to generate one.

Quoted 7 lines

Considering that they can't reasonably try to run any of these test programs (after all this is a cross build), wouldn't it suffice to make up crt*.o just for the configure process, and just providing the necessary symbols to make linking succeed? Agreed this, if anything, makes the present situation even uglier, but it might work.

Quoted 5 lines

It might. But that's not sustainable IMO.

One thing is that gmp configure doesn't try to run those test programs, because the configure rune doesn't indicate a cross-build, although it is actually one.

This is the key to fix this issue -- I didn't even notice it when I wrote this down!

After going through its configure script options, I found a way to make it aware of cross-compilation.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#6 lore raw
In reply to Wei Liu

Wei Liu writes ("Stubdom GMP build failure for gcc 6"):

Quoted 4 lines

Unfortunately my attempt to fix it by providing LDFLAGS="-nostdlib -LXXX" doesn't work. It turns out that there is no crt generated in newlib. I'm not sure if that's because the newlib port is incomplete or I haven't discovered a way to teach it to generate one.

How does stubdom link its actual final program, without a crt0 ?

Can we not just reproduce its link line somehow ?

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#7 lore raw
Quoted 8 lines · Ian Jackson

Wei Liu writes ("Stubdom GMP build failure for gcc 6"):

Quoted 4 lines

Unfortunately my attempt to fix it by providing LDFLAGS="-nostdlib -LXXX" doesn't work. It turns out that there is no crt generated in newlib. I'm not sure if that's because the newlib port is incomplete or I haven't discovered a way to teach it to generate one.

How does stubdom link its actual final program, without a crt0 ?

It chdir to mini-os and uses linker script provided there.

Quoted 2 lines

Can we not just reproduce its link line somehow ?

I don't think that would result in a program that can run on Linux.

Wei.

Quoted 1 line

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#8 lore raw

Wei Liu writes ("Re: Stubdom GMP build failure for gcc 6"):

Quoted 4 lines · Ian Jackson
Quoted 1 line

Can we not just reproduce its link line somehow ?

I don't think that would result in a program that can run on Linux.

Well, yes, sorry, I took it as read that we would say we were cross-compiling.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#9 lore raw
In reply to Wei Liu
Quoted 21 lines · Wei Liu

Hi all

There have been a few reports on stubdom build failure with gcc 6 toolchain. I spent some time yesterday to figure what went wrong. Here is what I found.

When building GMP library, its configure script generates small C programs to determine various aspects of the system. Unfortunately the build rune for it is incorrect, so the test program ends up consuming newlib headers while linking against the host glibc. It's amazing that this even worked in the past few years! :-)

Unfortunately my attempt to fix it by providing LDFLAGS="-nostdlib -LXXX" doesn't work. It turns out that there is no crt generated in newlib. I'm not sure if that's because the newlib port is incomplete or I haven't discovered a way to teach it to generate one.

So what should we do with this? I'm not sure if I can come up with a non-intrusive patch quickly. GMP is only used by tpm emulator, so for the imminent 4.8 release I can write a patch to disable building that.

Quoted 6 lines

Ultimately we need to have a proper solution, because there can be other breakages in the future. And I do wish users who need tpm emulator can continue to use it. I don't have a clear answer as to how many people care about this and how can we fix it.

Thoughts?

I just tried to verify it is working (or failing) for me. On the machine I normally did my Xen builds cmake was missing so it never tried to build libgmp. After installing it I saw the following problem:

at the end of libgmp build:
Libraries have been installed in:
/home/gross/xen/stubdom/cross-root-x86_64/x86_64-xen-elf/lib64

and when trying to link stubdom-vtpm:
make[2]: Entering directory '/home/gross/xen/extras/mini-os-remote' ld -r -d -nostdlib -L/home/gross/xen/stubdom/cross-root-x86_64/x86_64-xen-elf/lib -m elf_x86_64 -\( /home/gross/xen/stubdom/vtpm/vtpm.a -T app.lds -\) -ltpm -ltpm_crypto -lgmp -lpolarssl --undefined main -o /home/gross/xen/stubdom/mini-os-x86_64-vtpm/mini-os_app.o
ld: cannot find -lgmp

manually adding "-L/home/gross/xen/stubdom/cross-root-x86_64/x86_64-xen-elf/lib64" lets the link command succeed.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#10 lore raw
Quoted 46 lines · Juergen Gross
Quoted 21 lines · Wei Liu

Hi all

There have been a few reports on stubdom build failure with gcc 6 toolchain. I spent some time yesterday to figure what went wrong. Here is what I found.

When building GMP library, its configure script generates small C programs to determine various aspects of the system. Unfortunately the build rune for it is incorrect, so the test program ends up consuming newlib headers while linking against the host glibc. It's amazing that this even worked in the past few years! :-)

Unfortunately my attempt to fix it by providing LDFLAGS="-nostdlib -LXXX" doesn't work. It turns out that there is no crt generated in newlib. I'm not sure if that's because the newlib port is incomplete or I haven't discovered a way to teach it to generate one.

So what should we do with this? I'm not sure if I can come up with a non-intrusive patch quickly. GMP is only used by tpm emulator, so for the imminent 4.8 release I can write a patch to disable building that.

Quoted 6 lines

Ultimately we need to have a proper solution, because there can be other breakages in the future. And I do wish users who need tpm emulator can continue to use it. I don't have a clear answer as to how many people care about this and how can we fix it.

Thoughts?

I just tried to verify it is working (or failing) for me. On the machine I normally did my Xen builds cmake was missing so it never tried to build libgmp. After installing it I saw the following problem:

at the end of libgmp build:
Libraries have been installed in:

   /home/gross/xen/stubdom/cross-root-x86_64/x86_64-xen-elf/lib64

and when trying to link stubdom-vtpm:
make[2]: Entering directory '/home/gross/xen/extras/mini-os-remote' ld -r -d -nostdlib -L/home/gross/xen/stubdom/cross-root-x86_64/x86_64-xen-elf/lib -m elf_x86_64 -\( /home/gross/xen/stubdom/vtpm/vtpm.a -T app.lds -\) -ltpm -ltpm_crypto -lgmp -lpolarssl --undefined main -o /home/gross/xen/stubdom/mini-os-x86_64-vtpm/mini-os_app.o
ld: cannot find -lgmp

Quoted 4 lines

manually adding "-L/home/gross/xen/stubdom/cross-root-x86_64/x86_64-xen-elf/lib64" lets the link command succeed.

This is a different issue from the one I report here.

But both stems from the fact that we don't really create a complete cross-compile toolchain for stubdom, but piggy-back on the host toolchain.

Presumably you didn't see my issue because you're using an older version of glibc.

Wei.

Quoted 2 lines

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel