Recent

Author Topic: 32-bit RIP relative reference out of range error for string constants in Cocoa  (Read 3535 times)

LazProgger

  • Full Member
  • ***
  • Posts: 103
When using the "external string constants" defined in NSPasteboard or NSFileManager in 64-Bit Cocoa such as NSFileType, NSFileCreationDate, NSStringPboardType and so on, I get an error of the following type:

ld: 32-bit RIP relative reference out of range (-4297995934 max is +/-4GB): from _..._$$_...$crc9E1F315A (0x1002E35F0) to _NSStringPboardType@0x00000000 (0x00000000) in '_..._$$_...' from /Users/.../lib/x86_64-darwin/FileAttributes.o for architecture x86_64

In 32-Bit Carbon, the following was possible:

Code: Pascal  [Select][+][-]
  1. var
  2.   AKey: NSString;
  3. begin
  4.   AKey := NSURLIsHiddenKey; // or any other constant
  5. end;

Now, I always get this error, no matter how I use the constants. Also something like ANSMutableDictionary.setObject_forKey(ADate, NSFileModificationDate), what was possible in Carbon, is not possible when compiling for 64 Bit Cocoa.

Does someone have an idea what one can do here?
« Last Edit: August 09, 2019, 02:39:36 pm by LazProgger »

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Does someone have an idea what one can do here?
what are your compiler options used? any custom settings?

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
> Does someone have an idea what one can do here?

Are you sure you're using the 64 bit compiler?

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1059
> Does someone have an idea what one can do here?

Are you sure you're using the 64 bit compiler?
Yes, they are ("rip" is a 64 bit register).

My guess is that they disabled position-independent code (PIC; compiler option -Cg-).

LazProgger

  • Full Member
  • ***
  • Posts: 103
My guess is that they disabled position-independent code (PIC; compiler option -Cg-).

Thank you very much! That was it! I have removed the -Cg- compiler option and it is working now!

It was an old app made for Carbon. I cannot remember exactly, but probably I have read somewhere at that time that you need the -Cg- option for Carbon. Can that be? So, for Cocoa it seems to be different?!


Are you sure you're using the 64 bit compiler?

Yes, it was the 64 bit compiler. And my app is also showing as 64 bit in the Activity Monitor now.

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1059
My guess is that they disabled position-independent code (PIC; compiler option -Cg-).

Thank you very much! That was it! I have removed the -Cg- compiler option and it is working now!

It was an old app made for Carbon. I cannot remember exactly, but probably I have read somewhere at that time that you need the -Cg- option for Carbon. Can that be? So, for Cocoa it seems to be different?!
No, it was never necessary for Carbon. Someone may have suggested it to get faster code, but as you found it out, it can also result in unlinkable code.

LazProgger

  • Full Member
  • ***
  • Posts: 103
No, it was never necessary for Carbon. Someone may have suggested it to get faster code, but as you found it out, it can also result in unlinkable code.

Strange, I must have read it somewhere, otherwise I would have never come to the idea to add that option.

Just for knowledge: Is there a reason beyond getting faster code to use that option at all?

At least this thread can be found by other people now having the same problem.

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1059
Just for knowledge: Is there a reason beyond getting faster code to use that option at all?
No. It also makes it impossible to put the generated code in a (dynamic) library.

LazProgger

  • Full Member
  • ***
  • Posts: 103
No. It also makes it impossible to put the generated code in a (dynamic) library.

Okay. Thanks for clarification. I will remove that from all of my projects.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
If i remember correctly Apple requires ALL applications to be PIC (or PIE Position Independent Executable) to be publishable at App Store: https://developer.apple.com/library/archive/qa/qa1788/_index.html

LazProgger

  • Full Member
  • ***
  • Posts: 103
https://developer.apple.com/library/archive/qa/qa1788/_index.html

I have tested an application file, once created with the -Cg- option and once without with the tool mentioned in the link:

$ otool -hv /path/to/MyApp.app/MyApp

And both programs don't have the mentioned PIE flag.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
maybe it's iOS (arm) requirement.

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1059
Position-independent code (PIC) is a requirement for creating a position-independent executable (PIE), but the linker only creates a PIE executable by default if you target Mac OS X 10.7 or later (use the command line option -WM10.7 or higher; by default, FPC targets Mac OS X 10.5 for x86-64).

 

TinyPortal © 2005-2018