ld -r not working properly? - Aix

This is a discussion on ld -r not working properly? - Aix ; With our C++ application we need to let users link the application with gcc as opposed to g++. Under AIX 5.1 this worked fine by using "ld -r" on libstdc++.a and friends and merge all c++ dependencies into our objects ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: ld -r not working properly?

  1. ld -r not working properly?

    With our C++ application we need to let users link the application
    with gcc as opposed to g++. Under AIX 5.1 this worked fine by using
    "ld -r" on libstdc++.a and friends and merge all c++ dependencies into
    our objects before linking.
    However this doesn't work anymore under AIX 5.3 and g++ 4.2.3. It
    seems that ld only does a partial relinking and doesn't want to
    resolve all dependencies.

    As an example see t.cpp at the end.

    First I compile (but not link) it with g++:

    g++ -c -o t.o t.cpp

    Then I relink:

    ld -r t.o `g++ --print-file-name=libstdc++.a` `g++ --print-file-
    name=libgcc.a` -o t2.o

    As you can see the file size changes as expected:

    bash-3.2# ls -l *.o
    -rw-r--r-- 1 root system 692271 26 maj 00:26 t2.o
    -rw-r--r-- 1 root system 17749 26 maj 00:25 t.o

    However when I link with gcc I still get a bunch of linker errors. The
    same works on just about any unix platform we supply code on
    (including AIX 5.1 prior to upgrading).
    What I see is that symbols keep to be unresolved:

    bash-3.2# nm t2.o | grep .__cxa_rethrow
    ..__cxa_rethrow U -

    However libstdc++.a has the right symbols:
    bash-3.2# nm `g++ --print-file-name=libstdc++.a` | grep .__cxa_rethrow
    ..__cxa_rethrow t 268464120 180
    ..__cxa_rethrow T 268464120 180
    ..__cxa_rethrow T 269197968
    ..__cxa_rethrow t 269197968 40

    Could this be a bug in ld? I'm using TL08 though.

    Thanks.

    -- Henrik

    ---------
    bash-3.2# cat t.cpp
    #include
    #include
    #include
    #include

    using namespace std;

    int main()
    {
    list StrList;
    //char *p = new char[10001];

    StrList.push_back("test");

    printf("%s\n", StrList.begin()->c_str());

    //delete [] p;

    return 0;
    }



  2. Re: ld -r not working properly?

    hg@x-formation.com writes:

    > ld -r t.o `g++ --print-file-name=libstdc++.a` `g++ --print-file-
    > name=libgcc.a` -o t2.o


    On AIX (and only on AIX), libstdc++.a may or may not an archive
    library [1]. What does

    g++ --print-file-name=libstdc++.a | xargs ar tv

    say? If it lists shr.o, or some such, you'll probably have to
    rebuild gcc with --disable-shared (I warned you about this 2
    years ago, but you must have forgotten).

    > Could this be a bug in ld? I'm using TL08 though.


    Unlikely.

    Cheers,

    [1] It's an archive library all right, but unlike any other UNIX,
    it may contain shared objects; and so linking against it is
    equivalent to linking against libstdc++.so on other UNIXes.
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  3. Re: ld -r not working properly?

    > On AIX (and only on AIX), libstdc++.a may or may not an archive
    > library [1]. What does
    >
    > g++ --print-file-name=libstdc++.a | xargs ar tv
    >
    > say? If it lists shr.o, or some such, you'll probably have to
    > rebuild gcc with --disable-shared (I warned you about this 2
    > years ago, but you must have forgotten).
    >


    Thanks for your great help as always!

    Here is what it says:
    bash-3.2# g++ --print-file-name=libstdc++.a | xargs ar tv
    rwxr-xr-x 0/0 11246560 20 maj 18:24 2008 libstdc++.so.6

    Based on this I think you're right.
    Time to recompile... (24 hours of wait)

    I'm sure you told me before but I don't remember what I did last week and
    certainly not 2 years ago. I'll make sure to keep a note for this though!

    When done I'll report how it works out.

    -- Henrik


  4. Re: ld -r not working properly?

    Henrik Goldman wrote:
    >
    > Here is what it says:
    > bash-3.2# g++ --print-file-name=libstdc++.a | xargs ar tv
    > rwxr-xr-x 0/0 11246560 20 maj 18:24 2008 libstdc++.so.6
    >
    > Based on this I think you're right.
    > Time to recompile... (24 hours of wait)


    Um, try ld -r -bnso to turn the shared object into object code.

    Much faster :-)

  5. Re: ld -r not working properly?

    > Um, try ld -r -bnso to turn the shared object into object code.
    >
    > Much faster :-)


    Thanks for the suggestion. Too late now though as I went through the
    process.
    Fortunately it worked out perfectly and I'm up and running until next
    problem.

    Thanks.

    -- Henrik


+ Reply to Thread