-u option not working

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

-u option not working

Werner Volken
-u option not working Hi ,

The –u flag does not seem to work in the current distribution of odcctools.

For example if you compile a simple main.cpp with option –u for example:
 g++ test.cpp –uxyz

You get
 
/Volumes/opt/gcc/gcc410/bin/ld: unknown flag: -uxyz

Can this be fixed somehow?

Regards,

    Werner Volken
--
    
Werner Volken
     Obertärmu 35
   3911 Ried-Brig, Switzerland

    
phone numbers
       home     +41 27 924 2052
        office      +41 27 924 5171
        fax         +41 27 924 5132

     e-mail
       [hidden email]


_______________________________________________
odcctools mailing list
[hidden email]
http://www.opendarwin.org/mailman/listinfo/odcctools
Reply | Threaded
Open this post in threaded view
|

Re: -u option not working

Shantonu Sen-2
This behaves correctly. Also, before reporting bugs, please try to very if a stock version of Apple's cctools has the same issue, and if so, report the bug to Apple. If you believe you have a fix for an issue that you'd like in odcctools, that's a different issue, and patches are welcome.

In this case, the linker does not do getopt(3)-style argument processing, so the argument to the option -u must be separate by a space. So you have to have a space when you pass the option to the compiler driver.

[shantonu@shantonu-sens-powerbook-g4-12]$ cc foo.c -uxyz
/usr/bin/ld: unknown flag: -uxyz
collect2: ld returned 1 exit status
[shantonu@shantonu-sens-powerbook-g4-12]$ cc foo.c -u xyz
/usr/bin/ld: Undefined symbols:
xyz
collect2: ld returned 1 exit status
[shantonu@shantonu-sens-powerbook-g4-12]$ 

Shantonu

On Apr 21, 2006, at 4:45 AM, Werner Volken wrote:

Hi ,

The –u flag does not seem to work in the current distribution of odcctools.

For example if you compile a simple main.cpp with option –u for example:
 g++ test.cpp –uxyz

You get
 
/Volumes/opt/gcc/gcc410/bin/ld: unknown flag: -uxyz

Can this be fixed somehow?

Regards,

    Werner Volken
--
    
Werner Volken
     Obertärmu 35
   3911 Ried-Brig, Switzerland

    
phone numbers
       home     +41 27 924 2052
        office      +41 27 924 5171
        fax         +41 27 924 5132

     e-mail
       [hidden email]

_______________________________________________
odcctools mailing list


_______________________________________________
odcctools mailing list
[hidden email]
http://www.opendarwin.org/mailman/listinfo/odcctools
Reply | Threaded
Open this post in threaded view
|

Re: -u option not working

Shantonu Sen-2
In reply to this post by Werner Volken
Please reply to the list, not be personally.

The -u flag *does* mark it undefined. It just requires that you have a  
space between the -u and the symbol name. Use "-u xyz", not "-uxyz".

I can't explain it any better than that.

Shantonu

On Apr 24, 2006, at 2:35 AM, Werner Volken wrote:

> Thank you very much for your reply,
>
> I'm still not sure this is correct. The -u flag should put the  
> symbol xyz
> into the resulting object file and mark it as U (undefined)
>
> You can check this using with nm-command. At least gcc on Linux  
> works like
> this.
>
> On Linux:
> If you have some test.cpp
>
> test.cpp:
>
> #include <iostream>
>
> Int main(void) {
>     std::cout << "hello" << std::endl;
>     exit(0)
> }
>
> Now you can compile g++ test.cpp -uxyz and you get the executable  
> a.out.
> When you do 'nm a.out' you get something like this:
> .
> .
> 0000000000400860 T _start
> 0000000000400990 t __tcf_0
>                  U xyz
> 0000000000400952 t _Z41__static_initialization_and_destruction_0ii
> .
> .
> You can see the xyz symbol marked as U (undefined).
> I think this is what the -u flag should do.
>
> gcc on OSX does not behave like this.
> Do I understand something wrong?
>
> Regards,
>
>     Werner Volken
>
>
>> This behaves correctly. Also, before reporting bugs, please try to  
>> very if a
>> stock version of Apple's cctools has the same issue, and if so,  
>> report the bug
>> to Apple. If you believe you have a fix for an issue that you'd  
>> like in
>> odcctools, that's a different issue, and patches are welcome.
>>
>> In this case, the linker does not do getopt(3)-style argument  
>> processing, so
>> the argument to the option -u must be separate by a space. So you  
>> have to have
>> a space when you pass the option to the compiler driver.
>>
>> [shantonu@shantonu-sens-powerbook-g4-12]$ cc foo.c -uxyz
>> /usr/bin/ld: unknown flag: -uxyz
>> collect2: ld returned 1 exit status
>> [shantonu@shantonu-sens-powerbook-g4-12]$ cc foo.c -u xyz
>> /usr/bin/ld: Undefined symbols:
>> xyz
>> collect2: ld returned 1 exit status
>> [shantonu@shantonu-sens-powerbook-g4-12]$
>>
>> Shantonu
>>
>> On Apr 21, 2006, at 4:45 AM, Werner Volken wrote:
>>
>>>  Hi ,
>>>
>>>  The –u flag does not seem to work in the current distribution of  
>>> odcctools.
>>>
>>>  For example if you compile a simple main.cpp with option –u for  
>>> example:
>>>   g++ test.cpp –uxyz
>>>
>>>  You get
>>>
>>>  /Volumes/opt/gcc/gcc410/bin/ld: unknown flag: -uxyz
>>>
>>>  Can this be fixed somehow?
>>>
>>>  Regards,
>>>
>>>      Werner Volken
>>>  --
>>>      Werner Volken
>>>       Obertärmu 35
>>>      3911 Ried-Brig, Switzerland
>>>
>>>      phone numbers
>>>          home     +41 27 924 2052
>>>          office      +41 27 924 5171
>>>          fax         +41 27 924 5132
>>>
>>>       e-mail
>>>          [hidden email]
>>>
>>>
>>> _______________________________________________
>>> odcctools mailing list
>>> [hidden email]
>>> http://www.opendarwin.org/mailman/listinfo/odcctools
>>>
>>
>>
>
>
> --
>     Werner Volken
>      Obertärmu 35
>     3911 Ried-Brig, Switzerland
>
>     phone numbers
>         home     +41 27 924 2052
>         office      +41 27 924 5171
>         fax         +41 27 924 5132
>
>      e-mail
>         [hidden email]
>
>

_______________________________________________
odcctools mailing list
[hidden email]
http://www.opendarwin.org/mailman/listinfo/odcctools
Reply | Threaded
Open this post in threaded view
|

-u option not working

Werner Volken
In reply to this post by Werner Volken
[odcctools] -u option not working Thanks again for your reply Shantonu,

I used the form with space: –u xyz.
But at least on my machine (powermac G5, OSX 10.4.6, gcc 4.1.0)
I do not get any object file with xyz marked as undefined.

What I did:

1. take this code

#include <iostream>

Int main(void) {
    std::cout << "hello" << std::endl;
    exit(0)
}

2. Compile: g++ test.cpp –u xyz

I get:

/Volumes/opt/gcc/gcc410/bin/ld: Undefined symbols:
xyz
collect2: ld returned 1 exit status


So I don’t get the object file a.out.

The use of the -u option on Linux results in the executable a.out. Now if you look at a.out using the nm command, you can see something like this:

.
 .
 0000000000400860 T _start
 0000000000400990 t __tcf_0
                  U xyz
 0000000000400952 t _Z41__static_initialization_and_destruction_0ii
 .
 .

The symbol xyz is in the symbol table, and it is marked as U (undefined)

This is what happens on gcc 4.1.0 / Suse Linux and as far as I know this is what the –u flag should do:

-u sym Enter the argument sym into the symbol  table  as  an  undefined
              symbol.  This is useful for loading wholly from a library, since
              initially the symbol table is empty and an unresolved  reference
              is needed to force the loading of the first object file.


On OSX, I do not get any object file (executable).

What exactly do you mean If you say: The –u flag does mark it undefined?

Excuse me I’m just trying to understand,

Best regards,,

    Werner Volken



>Please reply to the list, not be personally.

> The -u flag *does* mark it undefined. It just requires that you have a  
> space between the -u and the symbol name. Use "-u xyz", not "-uxyz".
>
> I can't explain it any better than that.
>
> Shantonu
--
    
Werner Volken
     Obertärmu 35
   3911 Ried-Brig, Switzerland

    
phone numbers
       home     +41 27 924 2052
        office      +41 27 924 5171
        fax         +41 27 924 5132

     e-mail
       [hidden email]


_______________________________________________
odcctools mailing list
[hidden email]
http://www.opendarwin.org/mailman/listinfo/odcctools
Reply | Threaded
Open this post in threaded view
|

Re: -u option not working

Peter O'Gorman
On Mon, 2006-04-24 at 15:58 +0200, Werner Volken wrote:
> Thanks again for your reply Shantonu,
>
> I used the form with space: –u xyz.
> But at least on my machine (powermac G5, OSX 10.4.6, gcc 4.1.0)
> I do not get any object file with xyz marked as undefined.

> 2. Compile: g++ test.cpp –u xyz
>
> I get:
>
> /Volumes/opt/gcc/gcc410/bin/ld: Undefined symbols:
> xyz
> collect2: ld returned 1 exit status
>
>
> So I don’t get the object file a.out.
You're creating a two level namespace image which is not allowed to have
undefined symbols. Try it with '-flat_namespace -undefined warning'

Peter

_______________________________________________
odcctools mailing list
[hidden email]
http://www.opendarwin.org/mailman/listinfo/odcctools

signature.asc (318 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

-u option not working

Werner Volken
In reply to this post by Werner Volken
[odcctools] -u option not working Thank you very much,

This information was helpful.

Best Regards,

    Werner Volken

>You're creating a two level namespace image which is not allowed to have
>undefined symbols. Try it with '-flat_namespace -undefined warning'
--
    
Werner Volken
     Obertärmu 35
   3911 Ried-Brig, Switzerland

    
phone numbers
       home     +41 27 924 2052
        office      +41 27 924 5171
        fax         +41 27 924 5132

     e-mail
       [hidden email]


_______________________________________________
odcctools mailing list
[hidden email]
http://www.opendarwin.org/mailman/listinfo/odcctools
Reply | Threaded
Open this post in threaded view
|

Re: -u option not working

Adriaan van Os-5
In reply to this post by Peter O'Gorman
Peter O'Gorman wrote:

Werner Volken wrote:

>> Thanks again for your reply Shantonu,
>>
>> I used the form with space: –u xyz.
>> But at least on my machine (powermac G5, OSX 10.4.6, gcc 4.1.0)
>> I do not get any object file with xyz marked as undefined.
>
>> 2. Compile: g++ test.cpp –u xyz
>>
>> I get:
>>
>> /Volumes/opt/gcc/gcc410/bin/ld: Undefined symbols:
>> xyz
>> collect2: ld returned 1 exit status
>>
>>
>> So I don’t get the object file a.out.
>
> You're creating a two level namespace image which is not allowed to have
> undefined symbols. Try it with '-flat_namespace -undefined warning'

Note the difference between -U and -u
(<http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/ld.1.html>)

     -u sym Enter the argument sym into the symbol  table as an undefined
               symbol.  This is useful for loading wholly from a library, since
               initially the symbol table is empty and an unresolved  reference
               is needed to force the loading of the first object file.

  -U sym Allow the symbol sym to be undefined, even if the -r flag is not
               given.  Produce an executable file if the only undefined symbols
               are those specified with -U.

According to these docs, the namespace setting affects -U, not -u

        When  creating  an  output  file  with  the  static  link  editor  when
        -twolevel_namespace is in effect (now the default) all undefined refer-references
        ences  must be satisfied at static link time.  The flags to allow unde-undefined
        fined references, -Usymbol_name, -undefined warning and -undefined sup-suppress
        press  can't  be  used.   When  the environment variable MACOSX_DEPLOY-MACOSX_DEPLOYMENT_TARGET
        MENT_TARGET is set to 10.3 or higher then -undefined dynamic_lookup can
        also be used.

Regards,

Adriaan van Os

_______________________________________________
odcctools mailing list
[hidden email]
http://www.opendarwin.org/mailman/listinfo/odcctools
Reply | Threaded
Open this post in threaded view
|

-u option not working

Werner Volken
In reply to this post by Werner Volken
[odcctools] -u option not working Hi,

Thanks all for your replies. Maybe some background why the –u flag is important to me:

I am trying to generate a shared library by linking an object file (.o)
an archive (.a) and some other shared library (.so).
When linking the object code (.o) file I want to force some symbols to
be undefined, such that they are linked from the archive, where they are
defined. If I use the -u option on the g++ command line this is working fine on Linux but not on OSX.

It seems there is some incompatibility between Linux and OSX regarding this.
Of course these system are quite different.
However the documentation for the –u option in the man pages of g++ and ld is the same.

So I think I have to create a special Makefile in order to port the software to OSX

Regards,

    Werner Volken
--
    
Werner Volken
     Obertärmu 35
   3911 Ried-Brig, Switzerland

    
phone numbers
       home     +41 27 924 2052
        office      +41 27 924 5171
        fax         +41 27 924 5132

     e-mail
       [hidden email]


_______________________________________________
odcctools mailing list
[hidden email]
http://www.opendarwin.org/mailman/listinfo/odcctools