diff mbox

Building tests from multiple object files

Message ID 570CDEE6.3030808@redhat.com
State Not Applicable
Headers show

Commit Message

Florian Weimer April 12, 2016, 11:41 a.m. UTC
I'm still working on upstreaming our libresolv and NSS tests.  During 
that, I noticed the following.

The glibc makefiles do not provide a simple way to assemble a test 
binary from multiple object files.  One way to see this is to apply the 
attached harmless patch and then run

   make subdirs=elf check

(or whatever you do to run the test suite).  Linking the test fails with:

/home/fweimer/src/gnu/glibc/build/elf/tst-tlsalign-vars.o: In function 
`use_errno':
/home/fweimer/src/gnu/glibc/git/elf/tst-tlsalign-vars.c:36: undefined 
reference to `__libc_errno'
collect2: error: ld returned 1 exit status
../Rules:154: recipe for target 
'/home/fweimer/src/gnu/glibc/build/elf/tst-tlsalign-extern' failed

The apparent cause is that the second object file for the test was built 
against internal glibc headers.

The incorrect make rule for the elf/tst-tlsalign-vars.o target is 
created by o-iterator.mk.  I have not been able to figure out which of 
the inclusions triggered this.

Is there a quick fix for this?

Thanks,
Florian

Comments

Andreas Schwab April 12, 2016, 12:16 p.m. UTC | #1
Florian Weimer <fweimer@redhat.com> writes:

> The glibc makefiles do not provide a simple way to assemble a test binary
> from multiple object files.  One way to see this is to apply the attached
> harmless patch and then run
>
>   make subdirs=elf check
>
> (or whatever you do to run the test suite).  Linking the test fails with:
>
> /home/fweimer/src/gnu/glibc/build/elf/tst-tlsalign-vars.o: In function
> `use_errno':
> /home/fweimer/src/gnu/glibc/git/elf/tst-tlsalign-vars.c:36: undefined
> reference to `__libc_errno'
> collect2: error: ld returned 1 exit status
> ../Rules:154: recipe for target
> '/home/fweimer/src/gnu/glibc/build/elf/tst-tlsalign-extern' failed
>
> The apparent cause is that the second object file for the test was built
> against internal glibc headers.

No, the problem is that it is built with MODULE_NAME=libc.  It should be
nonlib, so it needs to be put on test-extras (and on extra-test-objs to
get dependency right).

Andreas.
Florian Weimer April 13, 2016, 1:06 p.m. UTC | #2
On 04/12/2016 02:16 PM, Andreas Schwab wrote:
> Florian Weimer <fweimer@redhat.com> writes:
>
>> The glibc makefiles do not provide a simple way to assemble a test binary
>> from multiple object files.  One way to see this is to apply the attached
>> harmless patch and then run
>>
>>    make subdirs=elf check
>>
>> (or whatever you do to run the test suite).  Linking the test fails with:
>>
>> /home/fweimer/src/gnu/glibc/build/elf/tst-tlsalign-vars.o: In function
>> `use_errno':
>> /home/fweimer/src/gnu/glibc/git/elf/tst-tlsalign-vars.c:36: undefined
>> reference to `__libc_errno'
>> collect2: error: ld returned 1 exit status
>> ../Rules:154: recipe for target
>> '/home/fweimer/src/gnu/glibc/build/elf/tst-tlsalign-extern' failed
>>
>> The apparent cause is that the second object file for the test was built
>> against internal glibc headers.
>
> No, the problem is that it is built with MODULE_NAME=libc.  It should be
> nonlib, so it needs to be put on test-extras (and on extra-test-objs to
> get dependency right).

Thanks, this fixed the build issue for me, also for my actual test.

Florian
diff mbox

Patch

diff --git a/elf/tst-tlsalign-vars.c b/elf/tst-tlsalign-vars.c
index 01b3501..840b079 100644
--- a/elf/tst-tlsalign-vars.c
+++ b/elf/tst-tlsalign-vars.c
@@ -2,6 +2,8 @@ 
    purpose of the test that these definitions be in a separate translation
    unit from the code using the variables.  */
 
+#include <errno.h>
+
 __thread int tdata1 = 1;
 __thread int tdata2 __attribute__ ((aligned (0x10))) = 2;
 __thread int tdata3 __attribute__ ((aligned (0x1000))) = 4;
@@ -26,3 +28,12 @@  unused (void)
   tbss2 = -5;
   tbss3 = -6;
 }
+
+
+int
+use_errno (int c)
+{
+  int e = errno;
+  errno = c;
+  return e;
+}