Opened 12 years ago

Closed 11 years ago

#1147 closed defect (needsinfo)

[NEEDS INFO] Fix malformed TOC linker error on OS X

Reported by: historic_bruno Owned by:
Priority: If Time Permits Milestone:
Component: Build & Packages Keywords: osx, build
Cc: Patch:

Description (last modified by historic_bruno)

On OS X, after performing a build and editing some source code, errors like the following occur:

ld: in ../../../binaries/system/libengine.a, malformed archive TOC entry for _MASK__PSRETURN_Scripting_SetupFailed, offset 164452311 is beyond end of file 14363576 for architecture x86_64

or equally disturbing:

ld: in ../../../binaries/system/libengine.a(!<arch> #1/20), archive member '!<arch> #1/20' with length 100644 is not mach-o or llvm bitcode for architecture x86_64

We've been working around this by performing make clean every time, but that's a slow and frustrating process. Apparently the problem is the library table of contents needs to be updated after a rebuild, and this isn't happening automatically with ar. A suggested fix is running ranlib after ar and before ld which I can confirm works (run ranlb on the affected library after you get the error, then make again and it works). I don't know about the other suggestion of using the -s option for ar, but that's worth testing too.

Change History (13)

comment:1 by historic_bruno, 12 years ago

Description: modified (diff)

comment:2 by Kieran P, 12 years ago

Milestone: Alpha 9Alpha 10
Priority: Should HaveNice to Have

in reply to:  description comment:3 by Philip Taylor, 12 years ago

Replying to historic_bruno:

We've been working around this by performing make clean every time, but that's a slow and frustrating process.

Sounds like a "rm ../../../binaries/system/*.a" would probably be a significantly less slow workaround for this problem, until it's fixed.

comment:4 by historic_bruno, 12 years ago

Description: modified (diff)

Actually I've started running ranlib ../../../binaries/system/*.a as a work around, once I learned of the cause :)

More info: Premake inserts an ar -rcs command into the makefile, which should be doing what we want, according to the ar manpage on Lion:

     -c      Whenever an archive is created, an informational message to that
             effect is written to standard error.  If the -c option is speci-
             fied, ar creates the archive silently.
     -r      Replace or add the specified files to the archive.  If the ar-
             chive does not exist a new archive file is created.  Files that
             replace existing files do not change the order of the files
             within the archive.  New files are appended to the archive unless
             one of the options -a, -b or -i is specified.
     -s      Write an object-file index into the archive, or update an exist-
             ing one, even if no other change is made to the archive.  You may
             use this modifier flag either with any operation, or alone.  Run-
             ning `ar s' on an archive is equivalent to running `ranlib' on
             it.

The last sentence is apparently not true, as running ranlib separately on the archive fixes the error.

Last edited 12 years ago by historic_bruno (previous) (diff)

comment:5 by Kieran P, 12 years ago

Keywords: build added; linker removed
Priority: Nice to HaveIf Time Permits

comment:6 by historic_bruno, 12 years ago

I'm not sure if this still occurs with the latest command line tools package, at least I haven't encountered it since switching. Of course it would be nice to fix it for Snow Leopard and/or older tools.

comment:7 by historic_bruno, 12 years ago

Resolution: worksforme
Status: newclosed

Marking as resolved with the latest command line tools.

comment:8 by Kieran P, 12 years ago

Resolution: worksforme
Status: closedreopened

Got the following invalid TOC error when compiling today. On Mac Lion, fully updated, latest development tools. Look like this issue is still alive.

==== Building pyrogenesis (release) ====
Linking pyrogenesis
ld: warning: directory not found for option '-L../../../libraries/cxxtest/lib'
ld: warning: directory not found for option '-L../../../libraries/valgrind/lib'
ld: warning: directory not found for option '-L/opt/local/lib'
ld: in ../../../binaries/system/libsimulation2.a, malformed archive TOC entry for vtable for CCmpObstructionManager, offset 132068723 is beyond end of file 27297032
 for architecture x86_64
collect2: ld returned 1 exit status
make[1]: *** [../../../binaries/system/pyrogenesis] Error 1
make: *** [pyrogenesis] Error 2

comment:9 by historic_bruno, 12 years ago

I'm surprised, I haven't seen that error in months (it used to occur almost every build when code changed). When you say latest development tools, do you mean Xcode?

comment:10 by historic_bruno, 12 years ago

Milestone: Alpha 10Alpha 11

comment:11 by Kieran P, 12 years ago

Milestone: Alpha 11Backlog

comment:12 by stwf, 11 years ago

I don't see this any more either, is it a specific kind of change that triggers it?

comment:13 by historic_bruno, 11 years ago

Cc: Yves removed
Milestone: Backlog
Resolution: needsinfo
Status: reopenedclosed
Summary: Fix malformed TOC linker error on OS X[NEEDS INFO] Fix malformed TOC linker error on OS X
Note: See TracTickets for help on using tickets.