Opened 9 years ago

Closed 9 years ago

#4984 closed bug (fixed)

OS X: ld: warning: -read_only_relocs cannot be used with x86_64

Reported by: igloo Owned by:
Priority: high Milestone: 7.2.1
Component: Compiler Version: 7.0.2
Keywords: Cc: william.knop.nospam@…, gale@…, johan.tibell@…
Operating System: MacOS X Architecture: x86_64 (amd64)
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

From http://www.haskell.org/pipermail/glasgow-haskell-users/2011-February/020086.html

I'm getting a warning from the linker when building programs using the 64-bit   
version of the release candidate on Mac OS X 10.6.                              
                                                                                
$ cat Hello.hs                                                                  
module Main where                                                               
main = putStrLn "Hello, World"                                                  
                                                                                
$ ~/ghc-7/bin/ghc -fforce-recomp Hello.hs                                       
[1 of 1] Compiling Main             ( Hello.hs, Hello.o )                       
Linking Hello ...                                                               
ld: warning: -read_only_relocs cannot be used with x86_64                       
                                                                                
It doesn't seem to cause a problem when actually running the programs, from what
I have seen so far.                                                             

Attachments (1)

read_only_relocs_fix.dpatch.tar.bz2 (116.0 KB) - added by altaic 9 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 9 years ago by altaic

Cc: william.knop.nospam@… added

I get two warnings using HEAD: {{{ld: warning: -read_only_relocs cannot be used with x86_64 ld: warning: could not create compact unwind for _ffi_call_unix64: does not use RBP or RSP based frame}}}

Are they both harmless?

comment:2 Changed 9 years ago by altaic

Sorry for the bad formatting of the previous message!

I get two warnings using HEAD:

ld: warning: -read_only_relocs cannot be used with x86_64
ld: warning: could not create compact unwind for _ffi_call_unix64: does not use RBP or RSP based frame

Are they both harmless?

comment:3 Changed 9 years ago by carter

Architecture: Unknown/Multiplex86_64 (amd64)
Operating System: Unknown/MultipleMacOS X
Version: 7.0.17.0.2

I've seen this error a bunch,

but at least in all the haskell-only code i've used works fine as such.

but would it affect how code that links to c/cpp libraries works?

comment:4 Changed 9 years ago by YitzGale

Cc: gale@… added

comment:5 Changed 9 years ago by tibbe

Cc: johan.tibell@… added

comment:6 Changed 9 years ago by altaic

The fix for the read_only_relocs warnings the is simple, but I'm having trouble attaching the patch because it is apparently too large for trac.

I haven't completely sorted out the compact unwind warnings yet-- the OS X 10.6 linker now defaults to creating compact unwinds, which is a good thing, however the unwind info for _ffi_call_unix64 can't be represented in the compact format. Someone more familiar with libffi may be able to figure out how to make _ffi_call_unix64 compatible with the compact unwind format. Otherwise, we may be able to pass the linker -no_compact_unwind, or possibly disable the warnings. Unfortunately, the option -warn_compact_unwind turns the warning on (which is the default), and -no_warn_compact_unwind does not exist. Furthermore, even though using -no_compact_unwind does turn off the generation of compact unwinds, for some reason the warnings still pop up when I run the test suite.

Changed 9 years ago by altaic

comment:7 Changed 9 years ago by altaic

Status: newpatch

comment:8 in reply to:  6 Changed 9 years ago by altaic

Should I open a new ticket for the compact unwinds issue?

In the meantime, here's a discussion regarding compact unwinds @ LLVMdev: http://groups.google.com/group/llvm-dev/browse_thread/thread/8baba4531a9feb07/139c9eba3525ebe

Nick Kledzik's response:

I dug into this.  Based on the .s files in bugzilla, the latest gcc is   
now adding dwarf unwind info to describe the function epilog.  If you   
run dwarfdump --eh-frame on the .o files made with the new compiler,   
you'll see extra dwarf unwind instructions at the end like: 
                 ... 
                 DW_CFA_advance_loc4 (64)  #<-- advance to near end of   
function 
                 DW_CFA_restore (rbp) 
                 DW_CFA_def_cfa (rsp, 8) 
                 DW_CFA_nop 
                 DW_CFA_nop 
The linker's conversion to compact unwind "runs" the dwarf unwind info   
for a function and then records the state at the end.  Adding unwind   
info for the epilog breaks this.  In the long term, I can add   
heuristics to the linker to detect that what looks like unwind info   
for the epilog and stop processing the dwarf instructions. 
The short term fix for gcc is to *not* add epilog unwind information   
for Darwin. 
Epilog unwind information is never needed for exception processing.   
Its only use is for debugging or sampling when you want to   
asynchronously make a stack back trace. 
-Nick

comment:9 Changed 9 years ago by carter

if they're not caused by the same problem, why not?

comment:10 Changed 9 years ago by altaic

They're both caused by new behavior in OS X 10.6's linker, and I thought they both would be fixable in the build system. Since it seems more involved, I'll open a new ticket.

comment:11 Changed 9 years ago by igloo

Re the -read_only_relocs flag, copumpkin and I did some digging. In http://www.opensource.apple.com/source/ld64/ld64-123.2/src/ld/Options.cpp we have:

			else if ( strcmp(arg, "-read_only_relocs") == 0 ) {
				switch ( parseTreatment(argv[++i]) ) {
					case kNULL:
					case kInvalid:
						throw "-read_only_relocs missing [ warning | error | suppress ]";
					case kWarning:
						fWarnTextRelocs = true;
						fAllowTextRelocs = true;
						break;
					case kSuppress:
						fWarnTextRelocs = false;
						fAllowTextRelocs = true;
						break;
					case kError:
						fWarnTextRelocs = false;
						fAllowTextRelocs = false;
						break;
	// check -read_only_relocs is not used with x86_64
	if ( fAllowTextRelocs ) {
		if ( (fArchitecture == CPU_TYPE_X86_64) && (fOutputKind != kKextBundle) ) {
			warning("-read_only_relocs cannot be used with x86_64");
			fAllowTextRelocs = false;
		}
	}

and http://www.opensource.apple.com/source/ld64/ld64-123.2/src/ld/parsers/lto_file.cpp says:

		if ( options.allowTextRelocs )
			model = LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC;
		else
			model = LTO_CODEGEN_PIC_MODEL_DYNAMIC;

So presumably we can't have allowTextRelocs on OS X 64 for the same reason that PIC is always on.

comment:12 Changed 9 years ago by igloo

The ld: warning: could not create compact unwind for _ffi_call_unix64: does not use RBP or RSP based frame part of the ticket is now #5019.

comment:13 Changed 9 years ago by igloo

Resolution: fixed
Status: patchclosed

Fixed in HEAD and 7.0.3:

Wed Mar  9 12:19:11 PST 2011  William Knop <william.knop.nospam@gmail.com>
  * Don't use read_only_relocs on darwin x86-64; fixes #4984
Note: See TracTickets for help on using tickets.