errno function, error TLS/non TLS

This is a discussion on errno function, error TLS/non TLS within the C Programming forums, part of the General Programming Boards category; Look at the end of http://cboard.cprogramming.com/showthread.php?t=101632 for the origin of this question. Well, on old programs, one often meets symbol ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    9

    errno function, error TLS/non TLS

    Look at the end of /usr/bin/ld: errno: TLS definition in /lib/libc.so.6 for the origin of this question.
    Well, on old programs, one often meets
    symbol errno, version GLIBC_2.0 not defined in file libc.so.6 with link time reference
    error, so I made a little library with
    Code:
    extern int (* __errno_location);
    int errno()
    {
      return(*__errno_location);
        }
    and preload this library with LD_PRELOAD. This library defines the errno function and allows me to use olds programs like Maple 5 or 7 on recent linux (Debian Etch for instance).
    This work well with libc6 on debian etch (libc <= 2.3)

    But since libc 2.7 there is errors at compilation. if I try to change the code in
    Code:
    extern int *__errno_location (void) __attribute__ ((__nothrow__)) __attribute__ ((__const__));
    int errno ()
    {
      return((*__errno_location ()));
        }
    good compilation using gcc -O2 -c -o lib-errno.o lib-errno.c but
    Code:
    $ gcc -shared -Wl,-soname,lib-errno -o lib-errno.so lib-errno.o
    give
    errno: TLS definition in /lib/libc.so.6 section .tbss mismatches non-TLS definition in lib-errno.o section .tex

    How can I make a little shared library define the errno function and so allows me to run olds programs?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It sounds like there is errno definition in libc.so.6, by the error message.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    9
    Hum, if you are right, this little library would be in that case useless. It's strange because if I make a gcc -E of the following file
    Code:
    #include <errno.h>
    main()
    {
      int i=errno;
    }
    I got
    Code:
    main()
    {
      int i=(*__errno_location ());
    }
    (no errno fonction)
    and
    ~$ strings /lib/libc-2.7.so | grep errno
    clnt_perrno
    __errno_location
    clnt_sperrno
    __h_errno_location
    h_errno
    ; errno = %s
    __libc_errno != 34 || buf != ((void *)0) || size
    Using gdb this small program, the only functions I meet are
    francois@hercule:~$ grep errno /tmp/gre
    francois@hercule:~$ gdb main
    0xb7dc9840 __errno_location
    0xb7e92c90 __h_errno_location
    0xb7e9f0e0 clnt_sperrno
    0xb7e9f280 clnt_perrno
    francois@hercule:~$
    Last edited by fran.b; 02-25-2009 at 03:54 AM. Reason: precision

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, that's what I'd expect. There is no FUNCTION called errno, and most often, there is no variable either, because it is some sort of special (per-thread, pointer) variable.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    9
    Quote Originally Posted by matsp View Post
    Yes, that's what I'd expect. There is no FUNCTION called errno, and most often, there is no variable either, because it is some sort of special (per-thread, pointer) variable.
    But why can I not make such a function?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The problem is that errno is not (normally) a function. The linker problem you are receiving says that you have the same symbol in different sections, .tbss and .tex - the latter is "code", and the former, I believe is "TLS bss", which is where uninitialized (zero-initialized) variables would end up.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Feb 2009
    Posts
    9
    No possibility to suppress the non function symbol?

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by fran.b View Post
    No possibility to suppress the non function symbol?
    No, and you probably shouldn't do that... [But I'm not 100% sure I understand what the actual problem is - is it that you have OLD applications that are linking to more modern C library implementations].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Feb 2009
    Posts
    9
    Quote Originally Posted by matsp View Post
    No, and you probably shouldn't do that... [But I'm not 100% sure I understand what the actual problem is - is it that you have OLD applications that are linking to more modern C library implementations].
    Yes it is the problem, and I don't know an issue to this now...

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Aside from recompiling the source of the application or having old libraries installed, I'm not sure what you can do to fix it. It is clearly a binary compatibility break.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #11
    Registered User
    Join Date
    Feb 2009
    Posts
    9
    Hum, I don't have the sources (it's a close (and rather dear) program), I use it under debian (since ham in fact) running it on woody, etch with my previous library lib-errno. In fact, now it's seems the only method is to LD_PRELOAD old libc6 or make an old libc6 environnement in a chroot .
    I know how do that but the LD_PRELOAD of my lib-errno.so was really more simple.

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by fran.b View Post
    Hum, I don't have the sources (it's a close (and rather dear) program), I use it under debian (since ham in fact) running it on woody, etch with my previous library lib-errno. In fact, now it's seems the only method is to LD_PRELOAD old libc6 or make an old libc6 environnement in a chroot .
    I know how do that but the LD_PRELOAD of my lib-errno.so was really more simple.
    But your hack to fix it with LD_PRELOAD of lib-errno.so is no guarantee that other things aren't broken.

    Have you asked the supplier of the software for an upgrade that works with newer C library versions (or do you have to pay extra for that?)

    Edit: Have you tried compiling the C library with "no-TLS" (not quite sure what the actual option to the configure script is, but basically, build a non-TLS version of the C library. If it is non-TLS, then it probably will have a (more) standard implementation of errno).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #13
    Registered User
    Join Date
    Feb 2009
    Posts
    9
    Quote Originally Posted by matsp View Post
    But your hack to fix it with LD_PRELOAD of lib-errno.so is no guarantee that other things aren't broken.

    Have you asked the supplier of the software for an upgrade that works with newer C library versions (or do you have to pay extra for that?)
    There is an upgrade (and I know how to crack it in fact) but no money to buy it and I don't want to use my crack.
    Edit: Have you tried compiling the C library with "no-TLS" (not quite sure what the actual option to the configure script is, but basically, build a non-TLS version of the C library. If it is non-TLS, then it probably will have a (more) standard implementation of errno).
    Good idea, I'm going to try this way. Thanks.

  14. #14
    Registered User
    Join Date
    Mar 2009
    Posts
    2
    I usually define errno as

    __thread int errno=0;

    I know this is really bad, but my job gets done.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 06:18 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21