OS constant cause "32-bit RIP relative reference out of range" linker error on x64

  • Hi,

    I'm trying to make x64 work on XCode 4 Mac OS 10.7, but whenever I use a
    system constant, such as kCFAllocatorDefault, I get this linker error (on
    x86 it works fine):

    ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic)
    not allowed in code signed PIE, but used in
    __ZN10MClipboard3SetE7MString7MBuffer from
    /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_teststub.o.
    To fix this warning, don't compile with -mdynamic-no-pic or link with
    -Wl,-no_pie
    final section layout:
        __TEXT/__text addr=0x1000012E0, size=0x0015B24B, fileOffset=0x000012E0,
    type=1
        __TEXT/__stubs addr=0x10015C52C, size=0x00000402,
    fileOffset=0x0015C52C, type'
        __TEXT/__stub_helper addr=0x10015C930, size=0x000006BE,
    fileOffset=0x0015C930, type1
        __TEXT/__gcc_except_tab addr=0x10015CFF0, size=0x0004DAA0,
    fileOffset=0x0015CFF0, type=0
        __TEXT/__const addr=0x1001AAA90, size=0x00007DDA,
    fileOffset=0x001AAA90, type=0
        __TEXT/__cstring addr=0x1001B286A, size=0x0000A1F0,
    fileOffset=0x001B286A, type
        __TEXT/__unwind_info addr=0x1001BCA5A, size=0x000041E8,
    fileOffset=0x001BCA5A, type!
        __TEXT/__eh_frame addr=0x1001C0C48, size=0x000233B0,
    fileOffset=0x001C0C48, type
        __DATA/__program_vars addr=0x1001E4000, size=0x00000028,
    fileOffset=0x001E4000, type)
        __DATA/__nl_symbol_ptr addr=0x1001E4028, size=0x00000010,
    fileOffset=0x001E4028, type(
        __DATA/__got addr=0x1001E4038, size=0x00000020, fileOffset=0x001E4038,
    type(
        __DATA/__la_symbol_ptr addr=0x1001E4058, size=0x00000558,
    fileOffset=0x001E4058, type&
        __DATA/__mod_init_func addr=0x1001E45B0, size=0x00000010,
    fileOffset=0x001E45B0, type2
        __DATA/__data addr=0x1001E45C0, size=0x00004950, fileOffset=0x001E45C0,
    type=0
        __DATA/__const addr=0x1001E8F10, size=0x00001688,
    fileOffset=0x001E8F10, type=0
        __DATA/__cfstring addr=0x1001EA598, size=0x00000020,
    fileOffset=0x001EA598, type
        __DATA/__bss addr=0x1001EA5C0, size=0x00001249, fileOffset=0x00000000,
    type$
        __DATA/__common addr=0x1001EB810, size=0x00088680,
    fileOffset=0x00000000, type$
    ld: 32-bit RIP relative reference out of range (-4295653407 max is +/-4GB):
    from __ZN10MClipboard3SetE7MString7MBuffer (0x1000A70B0) to
    <_kCFAllocatorDefault...> (0x00000000) in
    __ZN10MClipboard3SetE7MString7MBuffer from
    /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_teststub.o
    for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see
    invocation)

    What is wrong with that? It does that literally with all constants, stdout
    for example too...

    Thanks in advance,
    Vojtech
  • On Wed, June 13, 2012 6:16 am, Vojtech Meluzí­n wrote:

    > I'm trying to make x64 work on XCode 4 Mac OS 10.7, but whenever I use a
    system constant, such as kCFAllocatorDefault, I get this linker error
    (on x86 it works fine):
    >
    > ld: warning: PIE disabled. Absolute addressing (perhaps
    -mdynamic-no-pic) not allowed in code signed PIE, but used in
    [MClipboard::Set(MString, MBuffer)] from
    > /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_teststub.o.
    > To fix this warning, don't compile with -mdynamic-no-pic or link with
    -Wl,-no_pie
    > final section layout:
    > __TEXT/__text addr=0x1000012E0, size=0x0015B24B, fileOffset=0x000012E0,
    > type=1
    > …
    > __DATA/__common addr=0x1001EB810, size=0x00088680,
    fileOffset=0x00000000, type=24
    > ld: 32-bit RIP relative reference out of range (-4295653407 max is +/-4GB):
    > from MClipboard::Set(MString, MBuffer) (0x1000A70B0) to
    > <_kCFAllocatorDefault...> (0x00000000) in
    > MClipboard::Set(MString, MBuffer) from
    [C++ symbols demangled]
    > /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_teststub.o
    > for architecture x86_64
    > clang: error: linker command failed with exit code 1 (use -v to see
    > invocation)
    >
    > What is wrong with that? It does that literally with all constants, stdout
    > for example too...

    The error message itself says what's wrong, and how to fix it. If you want
    to sign an application, Lion requires that it be a position-independent
    executable (PIE), so the pieces of the app can be shifted to random
    locations, denying attackers consistent addresses for access to your code.

    My guess is that whatever library MClipboard::Set(MString, MBuffer) is
    declared in was "efficiently" compiled with -mdynamic-no-pic (Generate
    Position-Dependent Code) and linked with -no_pie (Don't Build Position
    Independent Executable). Search for these settings in your targets' Build
    Settings panel with "Position".

    Set the Generate (the compiler flag) to Yes, and Don't Build to No, as the
    error message

    > To fix this warning, don't compile with -mdynamic-no-pic or link with
    -Wl,-no_pie

    told you.

    — F

    --
    Fritz Anderson
    Xcode 4 Unleashed — x4u.manoverboard.org
    Fathers' Day. Need I say more?
  • Please reduce this down to a simple test case. Thanks!

    On Jun 13, 2012, at 4:16 AM, Vojtěch Meluzín <meldaproduction...> wrote:

    > Hi,
    >
    > I'm trying to make x64 work on XCode 4 Mac OS 10.7, but whenever I use a system constant, such as kCFAllocatorDefault, I get this linker error (on x86 it works fine):
    >
    >
    > ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in __ZN10MClipboard3SetE7MString7MBuffer from /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_teststub.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
    > final section layout:
    > __TEXT/__text addr=0x1000012E0, size=0x0015B24B, fileOffset=0x000012E0, type=1
    > __TEXT/__stubs addr=0x10015C52C, size=0x00000402, fileOffset=0x0015C52C, type=27
    > __TEXT/__stub_helper addr=0x10015C930, size=0x000006BE, fileOffset=0x0015C930, type=31
    > __TEXT/__gcc_except_tab addr=0x10015CFF0, size=0x0004DAA0, fileOffset=0x0015CFF0, type=0
    > __TEXT/__const addr=0x1001AAA90, size=0x00007DDA, fileOffset=0x001AAA90, type=0
    > __TEXT/__cstring addr=0x1001B286A, size=0x0000A1F0, fileOffset=0x001B286A, type=12
    > __TEXT/__unwind_info addr=0x1001BCA5A, size=0x000041E8, fileOffset=0x001BCA5A, type=21
    > __TEXT/__eh_frame addr=0x1001C0C48, size=0x000233B0, fileOffset=0x001C0C48, type=18
    > __DATA/__program_vars addr=0x1001E4000, size=0x00000028, fileOffset=0x001E4000, type=29
    > __DATA/__nl_symbol_ptr addr=0x1001E4028, size=0x00000010, fileOffset=0x001E4028, type=28
    > __DATA/__got addr=0x1001E4038, size=0x00000020, fileOffset=0x001E4038, type=28
    > __DATA/__la_symbol_ptr addr=0x1001E4058, size=0x00000558, fileOffset=0x001E4058, type=26
    > __DATA/__mod_init_func addr=0x1001E45B0, size=0x00000010, fileOffset=0x001E45B0, type=32
    > __DATA/__data addr=0x1001E45C0, size=0x00004950, fileOffset=0x001E45C0, type=0
    > __DATA/__const addr=0x1001E8F10, size=0x00001688, fileOffset=0x001E8F10, type=0
    > __DATA/__cfstring addr=0x1001EA598, size=0x00000020, fileOffset=0x001EA598, type=16
    > __DATA/__bss addr=0x1001EA5C0, size=0x00001249, fileOffset=0x00000000, type=24
    > __DATA/__common addr=0x1001EB810, size=0x00088680, fileOffset=0x00000000, type=24
    > ld: 32-bit RIP relative reference out of range (-4295653407 max is +/-4GB): from __ZN10MClipboard3SetE7MString7MBuffer (0x1000A70B0) to <_kCFAllocatorDefault...> (0x00000000) in __ZN10MClipboard3SetE7MString7MBuffer from /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_teststub.o for architecture x86_64
    > clang: error: linker command failed with exit code 1 (use -v to see invocation)
    >
    > What is wrong with that? It does that literally with all constants, stdout for example too...
    >
    > Thanks in advance,
    > Vojtech
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Xcode-users mailing list      (<Xcode-users...>)
    > Help/Unsubscribe/Update your Subscription:
    > https://lists.apple.com/mailman/options/xcode-users/<zarzycki...>
    >
    > This email sent to <zarzycki...>
  • I tried, but no luck. I also tried a different thing - I added a small code
    accessing the constant or stdout for example and it was fine! So it
    obviously depends on which source is being compiled, but the compiler
    arguments should be the same. One thing is that the "problematic" source
    code is huge, like hundreds of thousands of lines probably. Could that be a
    problem? Or is there something the source code can contain to cause this?
    Some pragma or something...

    Thanks in advance
    Vojtech

    2012/6/13 Dave Zarzycki <zarzycki...>

    > Please reduce this down to a simple test case. Thanks!
    >
    >
    > On Jun 13, 2012, at 4:16 AM, Vojtěch Meluzín <meldaproduction...>
    > wrote:
    >
    >> Hi,
    >>
    >> I'm trying to make x64 work on XCode 4 Mac OS 10.7, but whenever I use a
    > system constant, such as kCFAllocatorDefault, I get this linker error (on
    > x86 it works fine):
    >>
    >>
    >> ld: warning: PIE disabled. Absolute addressing (perhaps
    > -mdynamic-no-pic) not allowed in code signed PIE, but used in
    > __ZN10MClipboard3SetE7MString7MBuffer from
    > /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_teststub.o.
    > To fix this warning, don't compile with -mdynamic-no-pic or link with
    > -Wl,-no_pie
    >> final section layout:
    >> __TEXT/__text addr=0x1000012E0, size=0x0015B24B,
    > fileOffset=0x000012E0, type=1
    >> __TEXT/__stubs addr=0x10015C52C, size=0x00000402,
    > fileOffset=0x0015C52C, type=27
    >> __TEXT/__stub_helper addr=0x10015C930, size=0x000006BE,
    > fileOffset=0x0015C930, type=31
    >> __TEXT/__gcc_except_tab addr=0x10015CFF0, size=0x0004DAA0,
    > fileOffset=0x0015CFF0, type=0
    >> __TEXT/__const addr=0x1001AAA90, size=0x00007DDA,
    > fileOffset=0x001AAA90, type=0
    >> __TEXT/__cstring addr=0x1001B286A, size=0x0000A1F0,
    > fileOffset=0x001B286A, type=12
    >> __TEXT/__unwind_info addr=0x1001BCA5A, size=0x000041E8,
    > fileOffset=0x001BCA5A, type=21
    >> __TEXT/__eh_frame addr=0x1001C0C48, size=0x000233B0,
    > fileOffset=0x001C0C48, type=18
    >> __DATA/__program_vars addr=0x1001E4000, size=0x00000028,
    > fileOffset=0x001E4000, type=29
    >> __DATA/__nl_symbol_ptr addr=0x1001E4028, size=0x00000010,
    > fileOffset=0x001E4028, type=28
    >> __DATA/__got addr=0x1001E4038, size=0x00000020,
    > fileOffset=0x001E4038, type=28
    >> __DATA/__la_symbol_ptr addr=0x1001E4058, size=0x00000558,
    > fileOffset=0x001E4058, type=26
    >> __DATA/__mod_init_func addr=0x1001E45B0, size=0x00000010,
    > fileOffset=0x001E45B0, type=32
    >> __DATA/__data addr=0x1001E45C0, size=0x00004950,
    > fileOffset=0x001E45C0, type=0
    >> __DATA/__const addr=0x1001E8F10, size=0x00001688,
    > fileOffset=0x001E8F10, type=0
    >> __DATA/__cfstring addr=0x1001EA598, size=0x00000020,
    > fileOffset=0x001EA598, type=16
    >> __DATA/__bss addr=0x1001EA5C0, size=0x00001249,
    > fileOffset=0x00000000, type=24
    >> __DATA/__common addr=0x1001EB810, size=0x00088680,
    > fileOffset=0x00000000, type=24
    >> ld: 32-bit RIP relative reference out of range (-4295653407 max is
    > +/-4GB): from __ZN10MClipboard3SetE7MString7MBuffer (0x1000A70B0) to
    > <_kCFAllocatorDefault...> (0x00000000) in
    > __ZN10MClipboard3SetE7MString7MBuffer from
    > /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_teststub.o
    > for architecture x86_64
    >> clang: error: linker command failed with exit code 1 (use -v to see
    > invocation)
    >>
    >> What is wrong with that? It does that literally with all constants,
    > stdout for example too...
    >>
    >> Thanks in advance,
    >> Vojtech
    >> _______________________________________________
    >> Do not post admin requests to the list. They will be ignored.
    >> Xcode-users mailing list      (<Xcode-users...>)
    >> Help/Unsubscribe/Update your Subscription:
    >> https://lists.apple.com/mailman/options/xcode-users/<zarzycki...>
    >>
    >> This email sent to <zarzycki...>
    >
    >
  • No help so far...
    It seems that CLANG doesn't cause this error when there is just a small
    source code. So I tried to divide the source codes into small parts, this
    time this is the error...

    ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic)
    not allowed in code signed PIE, but used in __ZN14MConsoleStreamC2Ev from
    /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o.
    To fix this warning, don't compile with -mdynamic-no-pic or link with
    -Wl,-no_pie
    final section layout:
        __TEXT/__text addr=0x100001000, size=0x0015B280, fileOffset=0x00001000,
    type=1
        __TEXT/__stubs addr=0x10015C280, size=0x000003FC,
    fileOffset=0x0015C280, type=27
        __TEXT/__stub_helper addr=0x10015C67C, size=0x000006B4,
    fileOffset=0x0015C67C, type=31
        __TEXT/__gcc_except_tab addr=0x10015CD30, size=0x0004DA10,
    fileOffset=0x0015CD30, type=0
        __TEXT/__const addr=0x1001AA740, size=0x00007E00,
    fileOffset=0x001AA740, type=0
        __TEXT/__cstring addr=0x1001B2540, size=0x0000A2E8,
    fileOffset=0x001B2540, type=12
        __TEXT/__unwind_info addr=0x1001BC828, size=0x00004214,
    fileOffset=0x001BC828, type=21
        __TEXT/__eh_frame addr=0x1001C0A40, size=0x000235C0,
    fileOffset=0x001C0A40, type=18
        __DATA/__program_vars addr=0x1001E4000, size=0x00000028,
    fileOffset=0x001E4000, type=29
        __DATA/__nl_symbol_ptr addr=0x1001E4028, size=0x00000010,
    fileOffset=0x001E4028, type=28
        __DATA/__got addr=0x1001E4038, size=0x00000018, fileOffset=0x001E4038,
    type=28
        __DATA/__la_symbol_ptr addr=0x1001E4050, size=0x00000550,
    fileOffset=0x001E4050, type=26
        __DATA/__mod_init_func addr=0x1001E45A0, size=0x00000038,
    fileOffset=0x001E45A0, type=32
        __DATA/__data addr=0x1001E45E0, size=0x00004950, fileOffset=0x001E45E0,
    type=0
        __DATA/__const addr=0x1001E8F30, size=0x00001688,
    fileOffset=0x001E8F30, type=0
        __DATA/__cfstring addr=0x1001EA5B8, size=0x00000020,
    fileOffset=0x001EA5B8, type=16
        __DATA/__bss addr=0x1001EA5E0, size=0x00001268, fileOffset=0x00000000,
    type=24
        __DATA/__common addr=0x1001EB850, size=0x00088681,
    fileOffset=0x00000000, type=24
    ld: 32-bit RIP relative reference out of range (-4295071253 max is +/-4GB):
    from __ZN14MConsoleStreamC2Ev (0x1000195D0) to
    <___stdoutp...>(0x00000000) in __ZN14MConsoleStreamC2Ev from
    /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o
    for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see
    invocation)

    Please somebody help, CLANG is essentially unusable for me now, I'm
    thinking about going back to the creepy GCC and leave all that work from
    last week, when I was trying to persuade CLANG to work...

    Vojtech

    2012/6/14 Vojtěch Meluzín <meldaproduction...>

    > I tried, but no luck. I also tried a different thing - I added a small
    > code accessing the constant or stdout for example and it was fine! So it
    > obviously depends on which source is being compiled, but the compiler
    > arguments should be the same. One thing is that the "problematic" source
    > code is huge, like hundreds of thousands of lines probably. Could that be a
    > problem? Or is there something the source code can contain to cause this?
    > Some pragma or something...
    >
    > Thanks in advance
    > Vojtech
    >
    >
    > 2012/6/13 Dave Zarzycki <zarzycki...>
    >
    >> Please reduce this down to a simple test case. Thanks!
    >>
    >>
    >> On Jun 13, 2012, at 4:16 AM, Vojtěch Meluzín <meldaproduction...>
    >> wrote:
    >>
    >>> Hi,
    >>>
    >>> I'm trying to make x64 work on XCode 4 Mac OS 10.7, but whenever I use
    >> a system constant, such as kCFAllocatorDefault, I get this linker error (on
    >> x86 it works fine):
    >>>
    >>>
    >>> ld: warning: PIE disabled. Absolute addressing (perhaps
    >> -mdynamic-no-pic) not allowed in code signed PIE, but used in
    >> __ZN10MClipboard3SetE7MString7MBuffer from
    >> /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_teststub.o.
    >> To fix this warning, don't compile with -mdynamic-no-pic or link with
    >> -Wl,-no_pie
    >>> final section layout:
    >>> __TEXT/__text addr=0x1000012E0, size=0x0015B24B,
    >> fileOffset=0x000012E0, type=1
    >>> __TEXT/__stubs addr=0x10015C52C, size=0x00000402,
    >> fileOffset=0x0015C52C, type=27
    >>> __TEXT/__stub_helper addr=0x10015C930, size=0x000006BE,
    >> fileOffset=0x0015C930, type=31
    >>> __TEXT/__gcc_except_tab addr=0x10015CFF0, size=0x0004DAA0,
    >> fileOffset=0x0015CFF0, type=0
    >>> __TEXT/__const addr=0x1001AAA90, size=0x00007DDA,
    >> fileOffset=0x001AAA90, type=0
    >>> __TEXT/__cstring addr=0x1001B286A, size=0x0000A1F0,
    >> fileOffset=0x001B286A, type=12
    >>> __TEXT/__unwind_info addr=0x1001BCA5A, size=0x000041E8,
    >> fileOffset=0x001BCA5A, type=21
    >>> __TEXT/__eh_frame addr=0x1001C0C48, size=0x000233B0,
    >> fileOffset=0x001C0C48, type=18
    >>> __DATA/__program_vars addr=0x1001E4000, size=0x00000028,
    >> fileOffset=0x001E4000, type=29
    >>> __DATA/__nl_symbol_ptr addr=0x1001E4028, size=0x00000010,
    >> fileOffset=0x001E4028, type=28
    >>> __DATA/__got addr=0x1001E4038, size=0x00000020,
    >> fileOffset=0x001E4038, type=28
    >>> __DATA/__la_symbol_ptr addr=0x1001E4058, size=0x00000558,
    >> fileOffset=0x001E4058, type=26
    >>> __DATA/__mod_init_func addr=0x1001E45B0, size=0x00000010,
    >> fileOffset=0x001E45B0, type=32
    >>> __DATA/__data addr=0x1001E45C0, size=0x00004950,
    >> fileOffset=0x001E45C0, type=0
    >>> __DATA/__const addr=0x1001E8F10, size=0x00001688,
    >> fileOffset=0x001E8F10, type=0
    >>> __DATA/__cfstring addr=0x1001EA598, size=0x00000020,
    >> fileOffset=0x001EA598, type=16
    >>> __DATA/__bss addr=0x1001EA5C0, size=0x00001249,
    >> fileOffset=0x00000000, type=24
    >>> __DATA/__common addr=0x1001EB810, size=0x00088680,
    >> fileOffset=0x00000000, type=24
    >>> ld: 32-bit RIP relative reference out of range (-4295653407 max is
    >> +/-4GB): from __ZN10MClipboard3SetE7MString7MBuffer (0x1000A70B0) to
    >> <_kCFAllocatorDefault...> (0x00000000) in
    >> __ZN10MClipboard3SetE7MString7MBuffer from
    >> /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_teststub.o
    >> for architecture x86_64
    >>> clang: error: linker command failed with exit code 1 (use -v to see
    >> invocation)
    >>>
    >>> What is wrong with that? It does that literally with all constants,
    >> stdout for example too...
    >>>
    >>> Thanks in advance,
    >>> Vojtech
    >>> _______________________________________________
    >>> Do not post admin requests to the list. They will be ignored.
    >>> Xcode-users mailing list      (<Xcode-users...>)
    >>> Help/Unsubscribe/Update your Subscription:
    >>>
    >> https://lists.apple.com/mailman/options/xcode-users/<zarzycki...>
    >>>
    >>> This email sent to <zarzycki...>
    >>
    >>
    >
    >
  • On Jun 18, 2012, at 9:05 AM, Vojtěch Meluzín <meldaproduction...> wrote:

    > ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in __ZN14MConsoleStreamC2Ev from /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie

    You should fix the above first before trying to figure out the "32-bit RIP relative reference out of range" error.

    davez
  • I tried... but no compiler or linker options seem to have any effect
    here... And as I said it works with the same compiler options, but not with
    my sources and the only difference I can see is that the sources are huge,
    but minimizing them doesn't seem to help... No idea what to do know...

    Vojtech

    2012/6/18 Dave Zarzycki <zarzycki...>

    > On Jun 18, 2012, at 9:05 AM, Vojtěch Meluzín <meldaproduction...>
    > wrote:
    >
    > ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic)
    > not allowed in code signed PIE, but used in __ZN14MConsoleStreamC2Ev from
    > /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o.
    > To fix this warning, don't compile with -mdynamic-no-pic or link with
    > -Wl,-no_pie
    >
    >
    > You should fix the above first before trying to figure out the "32-bit RIP
    > relative reference out of range" error.
    >
    > davez
    >
  • In Xcode, for each project and for each target:

    1) Go to the build settings
    2) Type "dynamic-no-pic" into the search box
    3) Ensure that "Generate Position-Dependent Code" is either not set OR is explicitly set to NO
    4) Type "other_" into the search box
    5) Ensure that "-Wl,-no_pie" is NOT being passed via any of the various "Other … Flags" variables.

    On Jun 18, 2012, at 9:09 AM, Vojtěch Meluzín <meldaproduction...> wrote:

    > I tried... but no compiler or linker options seem to have any effect here... And as I said it works with the same compiler options, but not with my sources and the only difference I can see is that the sources are huge, but minimizing them doesn't seem to help... No idea what to do know...
    >
    > Vojtech
    >
    > 2012/6/18 Dave Zarzycki <zarzycki...>
    > On Jun 18, 2012, at 9:05 AM, Vojtěch Meluzín <meldaproduction...> wrote:
    >
    >> ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in __ZN14MConsoleStreamC2Ev from /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
    >
    > You should fix the above first before trying to figure out the "32-bit RIP relative reference out of range" error.
    >
    > davez
    >
    >
    >
    >
  • On 18 Jun 2012, at 11:05 AM, Vojtěch Meluzín wrote:

    > warning: PIE disabled. … To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie

    I mentioned this before, and if you reported on whether you tried it, I haven't seen it. I'll ask again: Have you tried doing what the warning says and enabling position-independent code/executable generation?

    — F
  • Open the build log and find the command lines that Xcode uses to compile one of your files, and to invoke the linker. Post them to the list.

    — F

    On 18 Jun 2012, at 11:09 AM, Vojtěch Meluzín wrote:

    > I tried... but no compiler or linker options seem to have any effect here... And as I said it works with the same compiler options, but not with my sources and the only difference I can see is that the sources are huge, but minimizing them doesn't seem to help... No idea what to do know...
  • Thanks folks, but no luck. Nothing for position dependent code is enabled.
    Linker arguments are below.
    Btw. as I mentioned - it does this only with the main source code I use,
    when I try to create a small test source with just a few lines accesing
    "stdout" or other static values which were causing the problem, it DOES
    work. It just doesn't for my main project executable, which is huge and
    that's the only difference I noticed. I thought maybe CLANG has some
    limitation for the code generations (like spacing methods by kilobytes =>
    too big project causes running over 32-bit space... no idea...).
    For the record, this is a clean Lion installation, but I also upgraded a
    while ago from Snow leopard and tried to use the new XCode and I ended with
    the same problem (on different machine, so it seems it does that on every
    Lion installation, no problem with settings or something...). But that time
    I didn't have any time, so I had to switch back to Snow leopard and XCode 3.

    Ok, the linker arguments:

    Ld
    /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug/console
    normal x86_64
        cd /Users/melda/Documents/console
        setenv MACOSX_DEPLOYMENT_TARGET 10.7

    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
    -arch x86_64 -isysroot
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk
    -L/Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug
    -F/Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug
    -filelist
    /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/console.LinkFileList
    -mmacosx-version-min=10.7 -framework AudioUnit -framework Cocoa -framework
    CoreAudio -framework CoreData -framework CoreServices -framework Security
    -o
    /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug/console

    And the output:

    ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic)
    not allowed in code signed PIE, but used in __ZN14MConsoleStreamC2Ev from
    /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o.
    To fix this warning, don't compile with -mdynamic-no-pic or link with
    -Wl,-no_pie
    final section layout:
        __TEXT/__text addr=0x100001000, size=0x0015B280, fileOffset=0x00001000,
    type=1
        __TEXT/__stubs addr=0x10015C280, size=0x000003FC,
    fileOffset=0x0015C280, type=27
        __TEXT/__stub_helper addr=0x10015C67C, size=0x000006B4,
    fileOffset=0x0015C67C, type=31
        __TEXT/__gcc_except_tab addr=0x10015CD30, size=0x0004DA10,
    fileOffset=0x0015CD30, type=0
        __TEXT/__const addr=0x1001AA740, size=0x00007E00,
    fileOffset=0x001AA740, type=0
        __TEXT/__cstring addr=0x1001B2540, size=0x0000A2E8,
    fileOffset=0x001B2540, type=12
        __TEXT/__unwind_info addr=0x1001BC828, size=0x00004214,
    fileOffset=0x001BC828, type=21
        __TEXT/__eh_frame addr=0x1001C0A40, size=0x000235C0,
    fileOffset=0x001C0A40, type=18
        __DATA/__program_vars addr=0x1001E4000, size=0x00000028,
    fileOffset=0x001E4000, type=29
        __DATA/__nl_symbol_ptr addr=0x1001E4028, size=0x00000010,
    fileOffset=0x001E4028, type=28
        __DATA/__got addr=0x1001E4038, size=0x00000018, fileOffset=0x001E4038,
    type=28
        __DATA/__la_symbol_ptr addr=0x1001E4050, size=0x00000550,
    fileOffset=0x001E4050, type=26
        __DATA/__mod_init_func addr=0x1001E45A0, size=0x00000038,
    fileOffset=0x001E45A0, type=32
        __DATA/__data addr=0x1001E45E0, size=0x00004950, fileOffset=0x001E45E0,
    type=0
        __DATA/__const addr=0x1001E8F30, size=0x00001688,
    fileOffset=0x001E8F30, type=0
        __DATA/__cfstring addr=0x1001EA5B8, size=0x00000020,
    fileOffset=0x001EA5B8, type=16
        __DATA/__bss addr=0x1001EA5E0, size=0x00001268, fileOffset=0x00000000,
    type=24
        __DATA/__common addr=0x1001EB850, size=0x00088681,
    fileOffset=0x00000000, type=24
    ld: 32-bit RIP relative reference out of range (-4295071253 max is +/-4GB):
    from __ZN14MConsoleStreamC2Ev (0x1000195D0) to
    <___stdoutp...>(0x00000000) in __ZN14MConsoleStreamC2Ev from
    /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o
    for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see
    invocation)

    2012/6/18 Dave Zarzycki <zarzycki...>

    > In Xcode, for each project and for each target:
    >
    > 1) Go to the build settings
    > 2) Type "dynamic-no-pic" into the search box
    > 3) Ensure that "Generate Position-Dependent Code" is either not set OR is
    > explicitly set to NO
    > 4) Type "other_" into the search box
    > 5) Ensure that "-Wl,-no_pie" is NOT being passed via any of the various
    > "Other … Flags" variables.
    >
    >
    > On Jun 18, 2012, at 9:09 AM, Vojtěch Meluzín <meldaproduction...>
    > wrote:
    >
    > I tried... but no compiler or linker options seem to have any effect
    > here... And as I said it works with the same compiler options, but not with
    > my sources and the only difference I can see is that the sources are huge,
    > but minimizing them doesn't seem to help... No idea what to do know...
    >
    > Vojtech
    >
    > 2012/6/18 Dave Zarzycki <zarzycki...>
    >
    >> On Jun 18, 2012, at 9:05 AM, Vojtěch Meluzín <meldaproduction...>
    >> wrote:
    >>
    >> ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic)
    >> not allowed in code signed PIE, but used in __ZN14MConsoleStreamC2Ev from
    >> /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o.
    >> To fix this warning, don't compile with -mdynamic-no-pic or link with
    >> -Wl,-no_pie
    >>
    >>
    >> You should fix the above first before trying to figure out the "32-bit
    >> RIP relative reference out of range" error.
    >>
    >> davez
    >>
    >
    >
    >
    >
    >
    >
  • Please check your per-file build settings, or simply just grep for dynamic-no-pic or no_pie in your Xcode project:

    grep dynamic-no-pic *.xcodeproj/project.pbxproj
    grep no_pie *.xcodeproj/project.pbxproj

    On Jun 18, 2012, at 3:55 PM, Vojtěch Meluzín <meldaproduction...> wrote:

    > Thanks folks, but no luck. Nothing for position dependent code is enabled. Linker arguments are below.
    > Btw. as I mentioned - it does this only with the main source code I use, when I try to create a small test source with just a few lines accesing "stdout" or other static values which were causing the problem, it DOES work. It just doesn't for my main project executable, which is huge and that's the only difference I noticed. I thought maybe CLANG has some limitation for the code generations (like spacing methods by kilobytes => too big project causes running over 32-bit space... no idea...).
    > For the record, this is a clean Lion installation, but I also upgraded a while ago from Snow leopard and tried to use the new XCode and I ended with the same problem (on different machine, so it seems it does that on every Lion installation, no problem with settings or something...). But that time I didn't have any time, so I had to switch back to Snow leopard and XCode 3.
    >
    > Ok, the linker arguments:
    >
    > Ld /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug/console normal x86_64
    > cd /Users/melda/Documents/console
    > setenv MACOSX_DEPLOYMENT_TARGET 10.7
    > /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -L/Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug -F/Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug -filelist /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/console.LinkFileList -mmacosx-version-min=10.7 -framework AudioUnit -framework Cocoa -framework CoreAudio -framework CoreData -framework CoreServices -framework Security -o /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug/console
    >
    >
    > And the output:
    >
    > ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in __ZN14MConsoleStreamC2Ev from /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
    > final section layout:
    > __TEXT/__text addr=0x100001000, size=0x0015B280, fileOffset=0x00001000, type=1
    > __TEXT/__stubs addr=0x10015C280, size=0x000003FC, fileOffset=0x0015C280, type=27
    > __TEXT/__stub_helper addr=0x10015C67C, size=0x000006B4, fileOffset=0x0015C67C, type=31
    > __TEXT/__gcc_except_tab addr=0x10015CD30, size=0x0004DA10, fileOffset=0x0015CD30, type=0
    > __TEXT/__const addr=0x1001AA740, size=0x00007E00, fileOffset=0x001AA740, type=0
    > __TEXT/__cstring addr=0x1001B2540, size=0x0000A2E8, fileOffset=0x001B2540, type=12
    > __TEXT/__unwind_info addr=0x1001BC828, size=0x00004214, fileOffset=0x001BC828, type=21
    > __TEXT/__eh_frame addr=0x1001C0A40, size=0x000235C0, fileOffset=0x001C0A40, type=18
    > __DATA/__program_vars addr=0x1001E4000, size=0x00000028, fileOffset=0x001E4000, type=29
    > __DATA/__nl_symbol_ptr addr=0x1001E4028, size=0x00000010, fileOffset=0x001E4028, type=28
    > __DATA/__got addr=0x1001E4038, size=0x00000018, fileOffset=0x001E4038, type=28
    > __DATA/__la_symbol_ptr addr=0x1001E4050, size=0x00000550, fileOffset=0x001E4050, type=26
    > __DATA/__mod_init_func addr=0x1001E45A0, size=0x00000038, fileOffset=0x001E45A0, type=32
    > __DATA/__data addr=0x1001E45E0, size=0x00004950, fileOffset=0x001E45E0, type=0
    > __DATA/__const addr=0x1001E8F30, size=0x00001688, fileOffset=0x001E8F30, type=0
    > __DATA/__cfstring addr=0x1001EA5B8, size=0x00000020, fileOffset=0x001EA5B8, type=16
    > __DATA/__bss addr=0x1001EA5E0, size=0x00001268, fileOffset=0x00000000, type=24
    > __DATA/__common addr=0x1001EB850, size=0x00088681, fileOffset=0x00000000, type=24
    > ld: 32-bit RIP relative reference out of range (-4295071253 max is +/-4GB): from __ZN14MConsoleStreamC2Ev (0x1000195D0) to <___stdoutp...> (0x00000000) in __ZN14MConsoleStreamC2Ev from /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o for architecture x86_64
    > clang: error: linker command failed with exit code 1 (use -v to see invocation)
    >
    >
    > 2012/6/18 Dave Zarzycki <zarzycki...>
    > In Xcode, for each project and for each target:
    >
    > 1) Go to the build settings
    > 2) Type "dynamic-no-pic" into the search box
    > 3) Ensure that "Generate Position-Dependent Code" is either not set OR is explicitly set to NO
    > 4) Type "other_" into the search box
    > 5) Ensure that "-Wl,-no_pie" is NOT being passed via any of the various "Other … Flags" variables.
    >
    >
    > On Jun 18, 2012, at 9:09 AM, Vojtěch Meluzín <meldaproduction...> wrote:
    >
    >> I tried... but no compiler or linker options seem to have any effect here... And as I said it works with the same compiler options, but not with my sources and the only difference I can see is that the sources are huge, but minimizing them doesn't seem to help... No idea what to do know...
    >>
    >> Vojtech
    >>
    >> 2012/6/18 Dave Zarzycki <zarzycki...>
    >> On Jun 18, 2012, at 9:05 AM, Vojtěch Meluzín <meldaproduction...> wrote:
    >>
    >>> ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in __ZN14MConsoleStreamC2Ev from /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
    >>
    >> You should fix the above first before trying to figure out the "32-bit RIP relative reference out of range" error.
    >>
    >> davez
    >>
    >>
    >>
    >>
    >
    >
    >
  • There seems to be no pbxproj file on my machine. Anyway you mean compiler
    settings for each source? The thing is, I tried using the small code
    accessing the constant and it works. Then I included the big source code in
    that small code that worked, and it stopped working! So it doesn't seem
    related to compiler options, because the same code once works and in other
    case it doesn't. I also tried invoking CLANG manually with the same results
    (and I ensured there is no dynamic-no-pic etc., in fact I tried maybe every
    possible combination...). Seems to me like a bug in CLANG.

    2012/6/19 Dave Zarzycki <zarzycki...>

    > Please check your per-file build settings, or simply just grep for
    > dynamic-no-pic or no_pie in your Xcode project:
    >
    > grep dynamic-no-pic *.xcodeproj/project.pbxproj
    > grep no_pie *.xcodeproj/project.pbxproj
    >
    >
    > On Jun 18, 2012, at 3:55 PM, Vojtěch Meluzín <meldaproduction...>
    > wrote:
    >
    > Thanks folks, but no luck. Nothing for position dependent code is enabled.
    > Linker arguments are below.
    > Btw. as I mentioned - it does this only with the main source code I use,
    > when I try to create a small test source with just a few lines accesing
    > "stdout" or other static values which were causing the problem, it DOES
    > work. It just doesn't for my main project executable, which is huge and
    > that's the only difference I noticed. I thought maybe CLANG has some
    > limitation for the code generations (like spacing methods by kilobytes =>
    > too big project causes running over 32-bit space... no idea...).
    > For the record, this is a clean Lion installation, but I also upgraded a
    > while ago from Snow leopard and tried to use the new XCode and I ended with
    > the same problem (on different machine, so it seems it does that on every
    > Lion installation, no problem with settings or something...). But that time
    > I didn't have any time, so I had to switch back to Snow leopard and XCode 3.
    >
    > Ok, the linker arguments:
    >
    > Ld
    > /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug/console
    > normal x86_64
    > cd /Users/melda/Documents/console
    > setenv MACOSX_DEPLOYMENT_TARGET 10.7
    >
    > /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
    > -arch x86_64 -isysroot
    > /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk
    > -L/Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug
    > -F/Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug
    > -filelist
    > /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/console.LinkFileList
    > -mmacosx-version-min=10.7 -framework AudioUnit -framework Cocoa -framework
    > CoreAudio -framework CoreData -framework CoreServices -framework Security
    > -o
    > /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug/console
    >
    >
    > And the output:
    >
    > ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic)
    > not allowed in code signed PIE, but used in __ZN14MConsoleStreamC2Ev from
    > /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o.
    > To fix this warning, don't compile with -mdynamic-no-pic or link with
    > -Wl,-no_pie
    > final section layout:
    > __TEXT/__text addr=0x100001000, size=0x0015B280,
    > fileOffset=0x00001000, type=1
    > __TEXT/__stubs addr=0x10015C280, size=0x000003FC,
    > fileOffset=0x0015C280, type=27
    > __TEXT/__stub_helper addr=0x10015C67C, size=0x000006B4,
    > fileOffset=0x0015C67C, type=31
    > __TEXT/__gcc_except_tab addr=0x10015CD30, size=0x0004DA10,
    > fileOffset=0x0015CD30, type=0
    > __TEXT/__const addr=0x1001AA740, size=0x00007E00,
    > fileOffset=0x001AA740, type=0
    > __TEXT/__cstring addr=0x1001B2540, size=0x0000A2E8,
    > fileOffset=0x001B2540, type=12
    > __TEXT/__unwind_info addr=0x1001BC828, size=0x00004214,
    > fileOffset=0x001BC828, type=21
    > __TEXT/__eh_frame addr=0x1001C0A40, size=0x000235C0,
    > fileOffset=0x001C0A40, type=18
    > __DATA/__program_vars addr=0x1001E4000, size=0x00000028,
    > fileOffset=0x001E4000, type=29
    > __DATA/__nl_symbol_ptr addr=0x1001E4028, size=0x00000010,
    > fileOffset=0x001E4028, type=28
    > __DATA/__got addr=0x1001E4038, size=0x00000018, fileOffset=0x001E4038,
    > type=28
    > __DATA/__la_symbol_ptr addr=0x1001E4050, size=0x00000550,
    > fileOffset=0x001E4050, type=26
    > __DATA/__mod_init_func addr=0x1001E45A0, size=0x00000038,
    > fileOffset=0x001E45A0, type=32
    > __DATA/__data addr=0x1001E45E0, size=0x00004950,
    > fileOffset=0x001E45E0, type=0
    > __DATA/__const addr=0x1001E8F30, size=0x00001688,
    > fileOffset=0x001E8F30, type=0
    > __DATA/__cfstring addr=0x1001EA5B8, size=0x00000020,
    > fileOffset=0x001EA5B8, type=16
    > __DATA/__bss addr=0x1001EA5E0, size=0x00001268, fileOffset=0x00000000,
    > type=24
    > __DATA/__common addr=0x1001EB850, size=0x00088681,
    > fileOffset=0x00000000, type=24
    > ld: 32-bit RIP relative reference out of range (-4295071253 max is
    > +/-4GB): from __ZN14MConsoleStreamC2Ev (0x1000195D0) to
    > <___stdoutp...> (0x00000000) in __ZN14MConsoleStreamC2Ev from
    > /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o
    > for architecture x86_64
    > clang: error: linker command failed with exit code 1 (use -v to see
    > invocation)
    >
    >
    > 2012/6/18 Dave Zarzycki <zarzycki...>
    >
    >> In Xcode, for each project and for each target:
    >>
    >> 1) Go to the build settings
    >> 2) Type "dynamic-no-pic" into the search box
    >> 3) Ensure that "Generate Position-Dependent Code" is either not set OR is
    >> explicitly set to NO
    >> 4) Type "other_" into the search box
    >> 5) Ensure that "-Wl,-no_pie" is NOT being passed via any of the various
    >> "Other … Flags" variables.
    >>
    >>
    >> On Jun 18, 2012, at 9:09 AM, Vojtěch Meluzín <meldaproduction...>
    >> wrote:
    >>
    >> I tried... but no compiler or linker options seem to have any effect
    >> here... And as I said it works with the same compiler options, but not with
    >> my sources and the only difference I can see is that the sources are huge,
    >> but minimizing them doesn't seem to help... No idea what to do know...
    >>
    >> Vojtech
    >>
    >> 2012/6/18 Dave Zarzycki <zarzycki...>
    >>
    >>> On Jun 18, 2012, at 9:05 AM, Vojtěch Meluzín <meldaproduction...>
    >>> wrote:
    >>>
    >>> ld: warning: PIE disabled. Absolute addressing (perhaps
    >>> -mdynamic-no-pic) not allowed in code signed PIE, but used in
    >>> __ZN14MConsoleStreamC2Ev from
    >>> /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o.
    >>> To fix this warning, don't compile with -mdynamic-no-pic or link with
    >>> -Wl,-no_pie
    >>>
    >>>
    >>> You should fix the above first before trying to figure out the "32-bit
    >>> RIP relative reference out of range" error.
    >>>
    >>> davez
    >>>
    >>
    >>
    >>
    >>
    >>
    >>
    >
    >
    >
  • This is your bug (it even generates the same error):

    #pragma GCC visibility push(hidden)
    #include <stdio.h>
    #pragma GCC visibility pop
    int main(void) { printf("%p\n", stdout); return 0; }

    Do not pragma push visibility before including headers.

    davez

    On Jun 18, 2012, at 4:10 PM, Vojtěch Meluzín <meldaproduction...> wrote:

    > There seems to be no pbxproj file on my machine. Anyway you mean compiler settings for each source? The thing is, I tried using the small code accessing the constant and it works. Then I included the big source code in that small code that worked, and it stopped working! So it doesn't seem related to compiler options, because the same code once works and in other case it doesn't. I also tried invoking CLANG manually with the same results (and I ensured there is no dynamic-no-pic etc., in fact I tried maybe every possible combination...). Seems to me like a bug in CLANG.
    >
    > 2012/6/19 Dave Zarzycki <zarzycki...>
    > Please check your per-file build settings, or simply just grep for dynamic-no-pic or no_pie in your Xcode project:
    >
    > grep dynamic-no-pic *.xcodeproj/project.pbxproj
    > grep no_pie *.xcodeproj/project.pbxproj
    >
    >
    > On Jun 18, 2012, at 3:55 PM, Vojtěch Meluzín <meldaproduction...> wrote:
    >
    >> Thanks folks, but no luck. Nothing for position dependent code is enabled. Linker arguments are below.
    >> Btw. as I mentioned - it does this only with the main source code I use, when I try to create a small test source with just a few lines accesing "stdout" or other static values which were causing the problem, it DOES work. It just doesn't for my main project executable, which is huge and that's the only difference I noticed. I thought maybe CLANG has some limitation for the code generations (like spacing methods by kilobytes => too big project causes running over 32-bit space... no idea...).
    >> For the record, this is a clean Lion installation, but I also upgraded a while ago from Snow leopard and tried to use the new XCode and I ended with the same problem (on different machine, so it seems it does that on every Lion installation, no problem with settings or something...). But that time I didn't have any time, so I had to switch back to Snow leopard and XCode 3.
    >>
    >> Ok, the linker arguments:
    >>
    >> Ld /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug/console normal x86_64
    >> cd /Users/melda/Documents/console
    >> setenv MACOSX_DEPLOYMENT_TARGET 10.7
    >> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -L/Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug -F/Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug -filelist /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/console.LinkFileList -mmacosx-version-min=10.7 -framework AudioUnit -framework Cocoa -framework CoreAudio -framework CoreData -framework CoreServices -framework Security -o /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug/console
    >>
    >>
    >> And the output:
    >>
    >> ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in __ZN14MConsoleStreamC2Ev from /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
    >> final section layout:
    >> __TEXT/__text addr=0x100001000, size=0x0015B280, fileOffset=0x00001000, type=1
    >> __TEXT/__stubs addr=0x10015C280, size=0x000003FC, fileOffset=0x0015C280, type=27
    >> __TEXT/__stub_helper addr=0x10015C67C, size=0x000006B4, fileOffset=0x0015C67C, type=31
    >> __TEXT/__gcc_except_tab addr=0x10015CD30, size=0x0004DA10, fileOffset=0x0015CD30, type=0
    >> __TEXT/__const addr=0x1001AA740, size=0x00007E00, fileOffset=0x001AA740, type=0
    >> __TEXT/__cstring addr=0x1001B2540, size=0x0000A2E8, fileOffset=0x001B2540, type=12
    >> __TEXT/__unwind_info addr=0x1001BC828, size=0x00004214, fileOffset=0x001BC828, type=21
    >> __TEXT/__eh_frame addr=0x1001C0A40, size=0x000235C0, fileOffset=0x001C0A40, type=18
    >> __DATA/__program_vars addr=0x1001E4000, size=0x00000028, fileOffset=0x001E4000, type=29
    >> __DATA/__nl_symbol_ptr addr=0x1001E4028, size=0x00000010, fileOffset=0x001E4028, type=28
    >> __DATA/__got addr=0x1001E4038, size=0x00000018, fileOffset=0x001E4038, type=28
    >> __DATA/__la_symbol_ptr addr=0x1001E4050, size=0x00000550, fileOffset=0x001E4050, type=26
    >> __DATA/__mod_init_func addr=0x1001E45A0, size=0x00000038, fileOffset=0x001E45A0, type=32
    >> __DATA/__data addr=0x1001E45E0, size=0x00004950, fileOffset=0x001E45E0, type=0
    >> __DATA/__const addr=0x1001E8F30, size=0x00001688, fileOffset=0x001E8F30, type=0
    >> __DATA/__cfstring addr=0x1001EA5B8, size=0x00000020, fileOffset=0x001EA5B8, type=16
    >> __DATA/__bss addr=0x1001EA5E0, size=0x00001268, fileOffset=0x00000000, type=24
    >> __DATA/__common addr=0x1001EB850, size=0x00088681, fileOffset=0x00000000, type=24
    >> ld: 32-bit RIP relative reference out of range (-4295071253 max is +/-4GB): from __ZN14MConsoleStreamC2Ev (0x1000195D0) to <___stdoutp...> (0x00000000) in __ZN14MConsoleStreamC2Ev from /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o for architecture x86_64
    >> clang: error: linker command failed with exit code 1 (use -v to see invocation)
    >>
    >>
    >> 2012/6/18 Dave Zarzycki <zarzycki...>
    >> In Xcode, for each project and for each target:
    >>
    >> 1) Go to the build settings
    >> 2) Type "dynamic-no-pic" into the search box
    >> 3) Ensure that "Generate Position-Dependent Code" is either not set OR is explicitly set to NO
    >> 4) Type "other_" into the search box
    >> 5) Ensure that "-Wl,-no_pie" is NOT being passed via any of the various "Other … Flags" variables.
    >>
    >>
    >> On Jun 18, 2012, at 9:09 AM, Vojtěch Meluzín <meldaproduction...> wrote:
    >>
    >>> I tried... but no compiler or linker options seem to have any effect here... And as I said it works with the same compiler options, but not with my sources and the only difference I can see is that the sources are huge, but minimizing them doesn't seem to help... No idea what to do know...
    >>>
    >>> Vojtech
    >>>
    >>> 2012/6/18 Dave Zarzycki <zarzycki...>
    >>> On Jun 18, 2012, at 9:05 AM, Vojtěch Meluzín <meldaproduction...> wrote:
    >>>
    >>>> ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in __ZN14MConsoleStreamC2Ev from /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
    >>>
    >>> You should fix the above first before trying to figure out the "32-bit RIP relative reference out of range" error.
    >>>
    >>> davez
    >>>
    >>>
    >>>
    >>>
    >>
    >>
    >>
    >
    >
    >
    >
  • Perfect!! It seems working!! Thank you!!

    Vojtech

    2012/6/19 Dave Zarzycki <zarzycki...>

    > This is your bug (it even generates the same error):
    >
    > #pragma GCC visibility push(hidden)
    > #include <stdio.h>
    > #pragma GCC visibility pop
    > int main(void) { printf("%p\n", stdout); return 0; }
    >
    > Do not pragma push visibility before including headers.
    >
    > davez
    >
    >
    > On Jun 18, 2012, at 4:10 PM, Vojtěch Meluzín <meldaproduction...>
    > wrote:
    >
    > There seems to be no pbxproj file on my machine. Anyway you mean compiler
    > settings for each source? The thing is, I tried using the small code
    > accessing the constant and it works. Then I included the big source code in
    > that small code that worked, and it stopped working! So it doesn't seem
    > related to compiler options, because the same code once works and in other
    > case it doesn't. I also tried invoking CLANG manually with the same results
    > (and I ensured there is no dynamic-no-pic etc., in fact I tried maybe every
    > possible combination...). Seems to me like a bug in CLANG.
    >
    > 2012/6/19 Dave Zarzycki <zarzycki...>
    >
    >> Please check your per-file build settings, or simply just grep for
    >> dynamic-no-pic or no_pie in your Xcode project:
    >>
    >> grep dynamic-no-pic *.xcodeproj/project.pbxproj
    >> grep no_pie *.xcodeproj/project.pbxproj
    >>
    >>
    >> On Jun 18, 2012, at 3:55 PM, Vojtěch Meluzín <meldaproduction...>
    >> wrote:
    >>
    >> Thanks folks, but no luck. Nothing for position dependent code is
    >> enabled. Linker arguments are below.
    >> Btw. as I mentioned - it does this only with the main source code I use,
    >> when I try to create a small test source with just a few lines accesing
    >> "stdout" or other static values which were causing the problem, it DOES
    >> work. It just doesn't for my main project executable, which is huge and
    >> that's the only difference I noticed. I thought maybe CLANG has some
    >> limitation for the code generations (like spacing methods by kilobytes =>
    >> too big project causes running over 32-bit space... no idea...).
    >> For the record, this is a clean Lion installation, but I also upgraded a
    >> while ago from Snow leopard and tried to use the new XCode and I ended with
    >> the same problem (on different machine, so it seems it does that on every
    >> Lion installation, no problem with settings or something...). But that time
    >> I didn't have any time, so I had to switch back to Snow leopard and XCode 3.
    >>
    >> Ok, the linker arguments:
    >>
    >> Ld
    >> /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug/console
    >> normal x86_64
    >> cd /Users/melda/Documents/console
    >> setenv MACOSX_DEPLOYMENT_TARGET 10.7
    >>
    >> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
    >> -arch x86_64 -isysroot
    >> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk
    >> -L/Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug
    >> -F/Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug
    >> -filelist
    >> /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/console.LinkFileList
    >> -mmacosx-version-min=10.7 -framework AudioUnit -framework Cocoa -framework
    >> CoreAudio -framework CoreData -framework CoreServices -framework Security
    >> -o
    >> /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Products/Debug/console
    >>
    >>
    >> And the output:
    >>
    >> ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic)
    >> not allowed in code signed PIE, but used in __ZN14MConsoleStreamC2Ev from
    >> /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o.
    >> To fix this warning, don't compile with -mdynamic-no-pic or link with
    >> -Wl,-no_pie
    >> final section layout:
    >> __TEXT/__text addr=0x100001000, size=0x0015B280,
    >> fileOffset=0x00001000, type=1
    >> __TEXT/__stubs addr=0x10015C280, size=0x000003FC,
    >> fileOffset=0x0015C280, type=27
    >> __TEXT/__stub_helper addr=0x10015C67C, size=0x000006B4,
    >> fileOffset=0x0015C67C, type=31
    >> __TEXT/__gcc_except_tab addr=0x10015CD30, size=0x0004DA10,
    >> fileOffset=0x0015CD30, type=0
    >> __TEXT/__const addr=0x1001AA740, size=0x00007E00,
    >> fileOffset=0x001AA740, type=0
    >> __TEXT/__cstring addr=0x1001B2540, size=0x0000A2E8,
    >> fileOffset=0x001B2540, type=12
    >> __TEXT/__unwind_info addr=0x1001BC828, size=0x00004214,
    >> fileOffset=0x001BC828, type=21
    >> __TEXT/__eh_frame addr=0x1001C0A40, size=0x000235C0,
    >> fileOffset=0x001C0A40, type=18
    >> __DATA/__program_vars addr=0x1001E4000, size=0x00000028,
    >> fileOffset=0x001E4000, type=29
    >> __DATA/__nl_symbol_ptr addr=0x1001E4028, size=0x00000010,
    >> fileOffset=0x001E4028, type=28
    >> __DATA/__got addr=0x1001E4038, size=0x00000018,
    >> fileOffset=0x001E4038, type=28
    >> __DATA/__la_symbol_ptr addr=0x1001E4050, size=0x00000550,
    >> fileOffset=0x001E4050, type=26
    >> __DATA/__mod_init_func addr=0x1001E45A0, size=0x00000038,
    >> fileOffset=0x001E45A0, type=32
    >> __DATA/__data addr=0x1001E45E0, size=0x00004950,
    >> fileOffset=0x001E45E0, type=0
    >> __DATA/__const addr=0x1001E8F30, size=0x00001688,
    >> fileOffset=0x001E8F30, type=0
    >> __DATA/__cfstring addr=0x1001EA5B8, size=0x00000020,
    >> fileOffset=0x001EA5B8, type=16
    >> __DATA/__bss addr=0x1001EA5E0, size=0x00001268,
    >> fileOffset=0x00000000, type=24
    >> __DATA/__common addr=0x1001EB850, size=0x00088681,
    >> fileOffset=0x00000000, type=24
    >> ld: 32-bit RIP relative reference out of range (-4295071253 max is
    >> +/-4GB): from __ZN14MConsoleStreamC2Ev (0x1000195D0) to
    >> <___stdoutp...> (0x00000000) in __ZN14MConsoleStreamC2Ev from
    >> /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o
    >> for architecture x86_64
    >> clang: error: linker command failed with exit code 1 (use -v to see
    >> invocation)
    >>
    >>
    >> 2012/6/18 Dave Zarzycki <zarzycki...>
    >>
    >>> In Xcode, for each project and for each target:
    >>>
    >>> 1) Go to the build settings
    >>> 2) Type "dynamic-no-pic" into the search box
    >>> 3) Ensure that "Generate Position-Dependent Code" is either not set OR
    >>> is explicitly set to NO
    >>> 4) Type "other_" into the search box
    >>> 5) Ensure that "-Wl,-no_pie" is NOT being passed via any of the various
    >>> "Other … Flags" variables.
    >>>
    >>>
    >>> On Jun 18, 2012, at 9:09 AM, Vojtěch Meluzín <meldaproduction...>
    >>> wrote:
    >>>
    >>> I tried... but no compiler or linker options seem to have any effect
    >>> here... And as I said it works with the same compiler options, but not with
    >>> my sources and the only difference I can see is that the sources are huge,
    >>> but minimizing them doesn't seem to help... No idea what to do know...
    >>>
    >>> Vojtech
    >>>
    >>> 2012/6/18 Dave Zarzycki <zarzycki...>
    >>>
    >>>> On Jun 18, 2012, at 9:05 AM, Vojtěch Meluzín <meldaproduction...>
    >>>> wrote:
    >>>>
    >>>> ld: warning: PIE disabled. Absolute addressing (perhaps
    >>>> -mdynamic-no-pic) not allowed in code signed PIE, but used in
    >>>> __ZN14MConsoleStreamC2Ev from
    >>>> /Users/melda/Library/Developer/Xcode/DerivedData/console-elzukurmumezgoaajfaamjcaoeol/Build/Intermediates/console.build/Debug/console.build/Objects-normal/x86_64/mlibrary_part_2.o.
    >>>> To fix this warning, don't compile with -mdynamic-no-pic or link with
    >>>> -Wl,-no_pie
    >>>>
    >>>>
    >>>> You should fix the above first before trying to figure out the "32-bit
    >>>> RIP relative reference out of range" error.
    >>>>
    >>>> davez
    >>>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>
    >>
    >>
    >
    >
    >
    >
  • On 19 juin 2012, at 01:33, Dave Zarzycki wrote:

    > This is your bug (it even generates the same error):
    >
    > #pragma GCC visibility push(hidden)
    > #include <stdio.h>
    > #pragma GCC visibility pop
    > int main(void) { printf("%p\n", stdout); return 0; }
    >
    > Do not pragma push visibility before including headers.
    >
    > davez
    >

    Any idea why? as written, this is voodoo! I can't see the relation between visibility and position independent code.

    Thanks,

    Jean-Denis
  • Jean-Denis MUYS wrote on Tue, 19 Jun 2012:

    > Any idea why? as written, this is voodoo! I can't see the relation
    > between visibility and position independent code.

    There are two ways to perform position-independent accesses on x86-64:
    a) take the instruction pointer register (RIP), and add a *32 bit*
    offset to it that represents the offset between the current code
    address and the data you want to access. Since Mac OS X does not
    support more than 2GB (or 4GB?) of statically allocated code/data per
    binary image (library, program, ...), even when these images are
    compiled for a 64 bit architecture, this offset will always fit in 32
    bits.
    b) use the technique from a) to load a full 64 bit address from the
    current binary' image's global offset table (GOT), which can obviously
    contain addresses that point to data/code located anywhere in the
    current process' 64 bit address space

    My guess: the compiler assumes that if a symbol is hidden, by
    definition cannot be accessed outside the current module. If a symbol
    cannot be accessed outside the current module, you do not have to pass
    via the GOT to get its address. Instead, you can just use the method
    from a) to access it. If you start hiding symbols defined in another
    library (such as libSystem in case of stdio.h), then this assumption
    obviously no longer holds true and you run into trouble.

    It's the classic C problem whereby an "extern" declaration in no way,
    shape or form tells you where or how this symbol is in fact defined
    (and I don't think there's a duct tape attribute for that yet). It
    obviously allows for flexibility, but it can also easily break any
    compiler that tries to be smart about it.

    Jonas
  • On Jun 19, 2012, at 12:30 AM, Jean-Denis MUYS <jdmuys...> wrote:

    >
    > On 19 juin 2012, at 01:33, Dave Zarzycki wrote:
    >
    >> This is your bug (it even generates the same error):
    >>
    >> #pragma GCC visibility push(hidden)
    >> #include <stdio.h>
    >> #pragma GCC visibility pop
    >> int main(void) { printf("%p\n", stdout); return 0; }
    >>
    >> Do not pragma push visibility before including headers.
    >>
    >> davez
    >>
    >
    > Any idea why? as written, this is voodoo! I can't see the relation between visibility and position independent code.

    When the visibility of a global variable is hidden, the compiler optimize access to it. Therefore, by changing the default visibility to hidden before including headers, we trick the compiler into thinking that library globals like "stdout" are located in our process, when they are not.

    davez
previous month june 2012 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Go to today