tpoechtrager / osxcross

Mac OS X cross toolchain for Linux, FreeBSD, OpenBSD and Android (Termux)
GNU General Public License v2.0
2.85k stars 320 forks source link

error when using libraries in mac #299

Closed dvirtz closed 2 years ago

dvirtz commented 2 years ago

while linking libraries built with osxcross clang 11 to create a library in native mac with apple-clang 11 I get the following failure from ld:

0  0x1050af198  __assert_rtn + 127
1  0x1050aff1d  mach_o::relocatable::Parser<x86_64>::makeSortedSymbolsArray(unsigned int*, unsigned int const*) (.cold.1) + 0
2  0x104fa9460  mach_o::relocatable::Parser<x86_64>::parse(mach_o::relocatable::ParserOptions const&) + 3022
3  0x104f9fd32  mach_o::relocatable::Parser<x86_64>::parse(unsigned char const*, unsigned long long, char const*, long, ld::File::Ordinal, mach_o::relocatable::ParserOptions const&) + 232
4  0x104fd56be  archive::File<x86_64>::makeObjectFileForMember(archive::File<x86_64>::Entry const*) const + 752
5  0x104fd4d02  archive::File<x86_64>::justInTimeforEachAtom(char const*, ld::File::AtomHandler&) const + 100
6  0x104ff590b  ld::tool::InputFiles::searchLibraries(char const*, bool, bool, bool, ld::File::AtomHandler&) const + 251
7  0x105001361  ld::tool::Resolver::resolveUndefines() + 153
8  0x105004035  ld::tool::Resolver::resolve() + 75
9  0x104f92044  main + 794
10  0x7fff7f6663d5  start + 1
A linker snapshot was created at:
    /tmp/libbeam-slicer.dylib-2021-08-14-083133.ld-snapshot
ld: Assertion failed: (cfiStartsArray[i] != cfiStartsArray[i-1]), function parse, file /Library/Caches/com.apple.xbs/Sources/ld64/ld64-520/src/ld/parsers/macho_relocatable_file.cpp, line 1954.

any idea?

tpoechtrager commented 2 years ago

Are you sure the library was built with Clang and not GCC? It usually happens with GCC... Also OSXCross Clang assumes ld64-609, you are using ld64-520.

dvirtz commented 2 years ago

I didn't use gcc. Not intentionally at least. Is there a way to tell that from the binary? Is there a way to build osxcross with ld64-520?

tpoechtrager commented 2 years ago

You could try to build the library with -mlinker-version=520 but there is absolutely no guarantee it will make the crash disappear.

dvirtz commented 2 years ago

eventually I rebuilt my toolchain and the errors went away