Skip to contentSkip to conversation

dtc build failures on OS X

PATCH In review Timur Tabi 5 participants 15 messages May 20, 2009 – Jul 16, 2009 10 messages not in the archive Kbuild

lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

I'm trying to build dtc on Mac OS X. The compilation seems to go okay, but the linker dies. First, it says this:

LD libfdt/libfdt.so
ld: unknown option: --version-script=libfdt/version.lds
collect2: ld returned 1 exit status

A Google search suggested that I can just delete the --version-script option. I did that, and now I get this error:

LD libfdt/libfdt.so
ld: unknown option: -soname
collect2: ld returned 1 exit status

This web page: http://lists.apple.com/archives/unix-porting/2003/Oct/msg00032.html
had some suggestions on how to fix that, so my Makefile now looks like this:

$(LIBFDT_lib):

        @$(VECHO) LD $@
        $(CC) $(LDFLAGS) -fPIC -Wl,-dylib_install_name -Wl,$(notdir
$@) -shared -o $(LIBFDT_objdir)/libfdt-$(DTC_VERSION).so $^
        ln -s libfdt-$(DTC_VERSION).so $(LIBFDT_objdir)/libfdt.so

But now I get this error:

LD libfdt/libfdt.so
Undefined symbols:
"_main", referenced from:

      start in crt1.10.5.o

ld: symbol(s) not found
collect2: ld returned 1 exit status

So now I'm stuck. Has anyone tried this before? Can anyone tell me how to fix this?

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#2 lore raw
In reply to a message not in the archive
Quoted 2 lines · Timur Tabi

I'm trying to build dtc on Mac OS X. The compilation seems to go okay, but the linker dies. First, it says this:

Well, I'm not surprised something has gone wrong - not much work has gone into making dtc portable yet (though it has been compiled on FreeBSD, at least).

Quoted 6 lines

LD libfdt/libfdt.so
ld: unknown option: --version-script=libfdt/version.lds
collect2: ld returned 1 exit status

A Google search suggested that I can just delete the --version-script option. I did that, and now I get this error:

Hrm. What toolchain are you using?

Quoted 14 lines

LD libfdt/libfdt.so
ld: unknown option: -soname
collect2: ld returned 1 exit status

This web page: http://lists.apple.com/archives/unix-porting/2003/Oct/msg00032.html
had some suggestions on how to fix that, so my Makefile now looks like this:

$(LIBFDT_lib):

        @$(VECHO) LD $@
        $(CC) $(LDFLAGS) -fPIC -Wl,-dylib_install_name -Wl,$(notdir
$@) -shared -o $(LIBFDT_objdir)/libfdt-$(DTC_VERSION).so $^
        ln -s libfdt-$(DTC_VERSION).so $(LIBFDT_objdir)/libfdt.so
Quoted 8 lines

But now I get this error:

LD libfdt/libfdt.so
Undefined symbols:
"_main", referenced from:

      start in crt1.10.5.o

ld: symbol(s) not found
collect2: ld returned 1 exit status

*That* looks like it's trying to build an executable, rather than a shared library. Hence including the crt1.o module, which wants to call main().

Quoted 2 lines

So now I'm stuck. Has anyone tried this before? Can anyone tell me how to fix this?

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#3 lore raw
In reply to a message not in the archive
Quoted 29 lines · Timur Tabi

I'm trying to build dtc on Mac OS X. The compilation seems to go okay, but the linker dies. First, it says this:

LD libfdt/libfdt.so
ld: unknown option: --version-script=libfdt/version.lds
collect2: ld returned 1 exit status

A Google search suggested that I can just delete the --version-script option. I did that, and now I get this error:

LD libfdt/libfdt.so
ld: unknown option: -soname
collect2: ld returned 1 exit status

This web page: http://lists.apple.com/archives/unix-porting/2003/Oct/msg00032.html
had some suggestions on how to fix that, so my Makefile now looks like this:

$(LIBFDT_lib):

        @$(VECHO) LD $@
        $(CC) $(LDFLAGS) -fPIC -Wl,-dylib_install_name -Wl,$(notdir
$@) -shared -o $(LIBFDT_objdir)/libfdt-$(DTC_VERSION).so $^
        ln -s libfdt-$(DTC_VERSION).so $(LIBFDT_objdir)/libfdt.so

But now I get this error:

LD libfdt/libfdt.so
Undefined symbols:
"_main", referenced from:

Quoted 6 lines
      start in crt1.10.5.o

ld: symbol(s) not found
collect2: ld returned 1 exit status

So now I'm stuck. Has anyone tried this before? Can anyone tell me how to fix this?

-shared is incorrect on mac os it's -dynamiclib
see attached patch

Best Regards,
J.

Quoted 1 line

From 37a2ddc183fa381cc025adf8e9d9d143029fe159 Mon Sep 17 00:00:00 2001

From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/[email protected]>
Date: Wed, 20 May 2009 09:50:31 +0200
Subject: [PATCH] add Mac OS X support

use dylib shared lib extention
allow to specifiy os specific shared lib link option
Mac OS use -dynamiclib instead of -shared, -install_name instead of -soname and does not support --version-script

to buid on it do

make OSX=y

---
 Makefile |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
Makefile +11 -3
index be0fc8b..d8b3353 100644
@@ -28,6 +28,14 @@ BINDIR = $(PREFIX)/bin
 LIBDIR = $(PREFIX)/lib
 INCLUDEDIR = $(PREFIX)/include
 
+ifdef OSX
+SHAREDLIB_EXT=dylib
+SHAREDLIB_LINK_OPTIONS=-dynamiclib -Wl,-install_name -Wl,
+else
+SHAREDLIB_EXT=so
+SHAREDLIB_LINK_OPTIONS=-shared -Wl,--version-script=$(LIBFDT_version) -Wl,-soname,
+endif
+
 #
 # Overall rules
 #
@@ -116,7 +124,7 @@ endif
 LIBFDT_objdir = libfdt
 LIBFDT_srcdir = libfdt
 LIBFDT_archive = $(LIBFDT_objdir)/libfdt.a
-LIBFDT_lib = $(LIBFDT_objdir)/libfdt.so
+LIBFDT_lib = $(LIBFDT_objdir)/libfdt.$(SHAREDLIB_EXT)
 LIBFDT_include = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_INCLUDES))
 LIBFDT_version = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_VERSION))
 
@@ -220,8 +228,8 @@ clean: libfdt_clean tests_clean
 
 $(LIBFDT_lib):
 	@$(VECHO) LD $@
-	$(CC) $(LDFLAGS) -fPIC -Wl,--version-script=$(LIBFDT_version) -Wl,-soname,$(notdir $@) -shared -o $(LIBFDT_objdir)/libfdt-$(DTC_VERSION).so $^
-	ln -s libfdt-$(DTC_VERSION).so $(LIBFDT_objdir)/libfdt.so
+	$(CC) $(LDFLAGS) -fPIC $(SHAREDLIB_LINK_OPTIONS)$(notdir $@) -o $(LIBFDT_objdir)/libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT) $^
+	ln -sf libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT) $(LIBFDT_objdir)/libfdt.$(SHAREDLIB_EXT)
 
 %.lex.c: %.l
 	@$(VECHO) LEX $@
Signature · 1 line
1.6.0.4

_______________________________________________
devicetree-discuss mailing list [email protected]
https://ozlabs.org/mailman/listinfo/devicetree-discuss

#18 lore raw
In reply to a message not in the archive
Quoted 2 lines

I'm trying to build dtc on Mac OS X. The compilation seems to go okay, but the linker dies.

It doesn't die, it just complains ;-)

You're trying to build a Linux shared library on OSX. This won't work. Not only are the command line options not the same, the semantics are totally different as well; importantly, the versioning mechanism is very different. Given that, you do not want to use a shared library at all -- just use a normal (static) library. IMNSHO that should be the default, on Linux as well...

Segher

#20 lore raw
In reply to a message not in the archive
Quoted 11 lines · Segher Boessenkool
Quoted 2 lines

I'm trying to build dtc on Mac OS X. The compilation seems to go okay, but the linker dies.

It doesn't die, it just complains ;-)

You're trying to build a Linux shared library on OSX. This won't work. Not only are the command line options not the same, the semantics are totally different as well; importantly, the versioning mechanism is very different. Given that, you do not want to use a shared library at all -- just use a normal (static) library. IMNSHO that should be the default, on Linux as well...

It was, originally, but someone wanted a shared lib.

Actually, the current Makefile builds both, by default.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#22 lore raw
In reply to a message not in the archive
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

I'm trying to build dtc on Mac OS X. The compilation seems to go okay, but the linker dies.

It doesn't die, it just complains ;-)

Quoted 8 lines
Quoted 6 lines

You're trying to build a Linux shared library on OSX. This won't work. Not only are the command line options not the same, the semantics are totally different as well; importantly, the versioning mechanism is very different. Given that, you do not want to use a shared library at all -- just use a normal (static) library. IMNSHO that should be the default, on Linux as well...

It was, originally, but someone wanted a shared lib.

And you decided to take on all that maintenance pain? You're too good for this world. Or gullible, heh.

Quoted 1 line

Actually, the current Makefile builds both, by default.

It shouldn't try to build Linux shared objects unless you are building a Linux target; easiest would be to just never build the shared library by default. Your choice :-)

Segher

#24 lore raw
In reply to a message not in the archive
Quoted 12 lines · Segher Boessenkool
Quoted 12 lines
Quoted 11 lines
Quoted 2 lines

I'm trying to build dtc on Mac OS X. The compilation seems to go okay, but the linker dies.

It doesn't die, it just complains ;-)

You're trying to build a Linux shared library on OSX. This won't work. Not only are the command line options not the same, the semantics are totally different as well; importantly, the versioning mechanism is very different. Given that, you do not want to use a shared library at all -- just use a normal (static) library. IMNSHO that should be the default, on Linux as well...

Quoted 4 lines
Quoted 1 line

It was, originally, but someone wanted a shared lib.

And you decided to take on all that maintenance pain? You're too good for this world. Or gullible, heh.

Something like that.

Quoted 5 lines
Quoted 1 line

Actually, the current Makefile builds both, by default.

It shouldn't try to build Linux shared objects unless you are building a Linux target; easiest would be to just never build the shared library by default. Your choice :-)

Well, to be fair, the current rule should be right, or close to it, for most ELF systems, not just Linux.

Actually, another issue with this is that currently we build all the libfdt objects with -fPIC, which significantly increases their size. That tends to frighten people who are looking at building libfdt into their firmware.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#7 lore raw

PATCH v2 1/1 add Mac OS X support

In reply to a message not in the archive

use dylib shared lib extention
allow to specifiy os specific shared lib link option
Mac OS use -dynamiclib instead of -shared, -install_name instead of -soname and does not support --version-script

add HOSTOS macro to detect the current os you are

---
V2
detect dynamicly the host OS

 Makefile |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)
Makefile +14 -3
index be0fc8b..d7549b2 100644
@@ -28,6 +28,17 @@ BINDIR = $(PREFIX)/bin
 LIBDIR = $(PREFIX)/lib
 INCLUDEDIR = $(PREFIX)/include
 
+HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
+	    sed -e 's/\(cygwin\).*/cygwin/')
+
+ifeq ($(HOSTOS),darwin)
+SHAREDLIB_EXT=dylib
+SHAREDLIB_LINK_OPTIONS=-dynamiclib -Wl,-install_name -Wl,
+else
+SHAREDLIB_EXT=so
+SHAREDLIB_LINK_OPTIONS=-shared -Wl,--version-script=$(LIBFDT_version) -Wl,-soname,
+endif
+
 #
 # Overall rules
 #
@@ -116,7 +127,7 @@ endif
 LIBFDT_objdir = libfdt
 LIBFDT_srcdir = libfdt
 LIBFDT_archive = $(LIBFDT_objdir)/libfdt.a
-LIBFDT_lib = $(LIBFDT_objdir)/libfdt.so
+LIBFDT_lib = $(LIBFDT_objdir)/libfdt.$(SHAREDLIB_EXT)
 LIBFDT_include = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_INCLUDES))
 LIBFDT_version = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_VERSION))
 
@@ -220,8 +231,8 @@ clean: libfdt_clean tests_clean
 
 $(LIBFDT_lib):
 	@$(VECHO) LD $@
-	$(CC) $(LDFLAGS) -fPIC -Wl,--version-script=$(LIBFDT_version) -Wl,-soname,$(notdir $@) -shared -o $(LIBFDT_objdir)/libfdt-$(DTC_VERSION).so $^
-	ln -s libfdt-$(DTC_VERSION).so $(LIBFDT_objdir)/libfdt.so
+	$(CC) $(LDFLAGS) -fPIC $(SHAREDLIB_LINK_OPTIONS)$(notdir $@) -o $(LIBFDT_objdir)/libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT) $^
+	ln -sf libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT) $(LIBFDT_objdir)/libfdt.$(SHAREDLIB_EXT)
 
 %.lex.c: %.l
 	@$(VECHO) LEX $@
Signature · 1 line
1.6.0.4
author Acked-by
#9 lore raw

Re: [PATCH V2] add Mac OS X support

In reply to a message not in the archive
Quoted 8 lines · Jean-Christophe PLAGNIOL-VILLARD

use dylib shared lib extention
allow to specifiy os specific shared lib link option
Mac OS use -dynamiclib instead of -shared, -install_name instead of -soname and does not support --version-script

add HOSTOS macro to detect the current os you are

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#10 lore raw

Re: [PATCH V2] add Mac OS X support

In reply to a message not in the archive
Quoted 9 lines · Jean-Christophe PLAGNIOL-VILLARD

use dylib shared lib extention
allow to specifiy os specific shared lib link option
Mac OS use -dynamiclib instead of -shared, -install_name instead of -soname and does not support --version-script

add HOSTOS macro to detect the current os you are

---

jdl do you have any plan to apply it?

Best Regards,
J.

author
#12 lore raw

Re: [PATCH V2] add Mac OS X support

In reply to a message not in the archive

Jon, are you still updating dtc.git?

Quoted 19 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 9 lines · Jean-Christophe PLAGNIOL-VILLARD

use dylib shared lib extention
allow to specifiy os specific shared lib link option
Mac OS use -dynamiclib instead of -shared, -install_name instead of -soname and does not support --version-script

add HOSTOS macro to detect the current os you are

---

jdl do you have any plan to apply it?

Best Regards,
J.
_______________________________________________
devicetree-discuss mailing list [email protected]
https://ozlabs.org/mailman/listinfo/devicetree-discuss

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
author
#16 lore raw

Re: [PATCH V2] add Mac OS X support

In reply to a message not in the archive
Quoted 3 lines · Jon Loeliger
Quoted 1 line

Jon, are you still updating dtc.git?

Yep.

Then would you be so kind as to apply my patch, if you have no objections?

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#17 lore raw

Re: [PATCH V2] add Mac OS X support

In reply to a message not in the archive
Quoted 11 lines

use dylib shared lib extention
allow to specifiy os specific shared lib link option
Mac OS use -dynamiclib instead of -shared, -install_name instead of -soname and does not support --version-script

add HOSTOS macro to detect the current os you are

---
V2
detect dynamicly the host OS

Applied and pushed out.

Thanks,
jdl