Linking to Linux on a FreeBSD system with Linux emulated ?

classic Classic list List threaded Threaded
38 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Linking to Linux on a FreeBSD system with Linux emulated ?

fredvs
Hello.

In a FreeBSD 64 system with Linux emulated, fpc-linux compiles without problems but at linking there is that message:

> ... Linking
> /usr/bin/ld: unrecognizer emulation mode: elf_x86_64
> Supported emulation: elf_x86_64_fbsd and elf_i386_fbsd

In ld documentation there is:

-memulation
Emulate the emulation linker. You can list the available emulations with the `--verbose' or `-V' options. If the `-m' option is not used, the emulation is taken from the LDEMULATION environment variable, if that is defined. Otherwise, the default emulation depends upon how the linker was configured.

Could it be possible to change the default emulation used by ld while linking ?

Many thanks.

Fre;D
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

Jonas Maebe-2
On 01/09/16 18:32, fredvs wrote:
> Could it be possible to change the default emulation used by ld while
> linking ?

With fpc's -k parameter, you can pass parameters directly to the linker.
If you need to pass multiple parameters, use -k several times (e.g.
-k-para1 -kvalue1)


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

fredvs
> With fpc's -k parameter, you can pass parameters directly to the linker.
> If you need to pass multiple parameters, use -k several times (e.g.-k-para1 -kvalue1)

Wow, many thanks Jonas.

I will try it and write you the result.

But, imagine, with FreeBSD, you could:
Compile and run on same system (no need virtual-box to test it):
- FreeBSD 64 bit programs.
- FreeBSD 32 bit programs.
- Linux 64 bit programs.
- Linux 32 bit programs.
- Windows 64 bit programs (via wine).
- Windows 32 bit programs (via wine).
- Maybe other program-system too (via emulator).

Fre;D
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

Sven Barth-2

Am 01.09.2016 18:56 schrieb "fredvs" <[hidden email]>:
>
> > With fpc's -k parameter, you can pass parameters directly to the linker.
> > If you need to pass multiple parameters, use -k several times
> > (e.g.-k-para1 -kvalue1)
>
> Wow, many thanks Jonas.
>
> I will try it and write you the result.
>
> But, imagine, with FreeBSD, you could:
> Compile and run on same system (no need virtual-box to test it):
> - FreeBSD 64 bit programs.
> - FreeBSD 32 bit programs.
> - Linux 64 bit programs.
> - Linux 32 bit programs.
> - Windows 64 bit programs (via wine).
> - Windows 32 bit programs (via wine).
> - Maybe other program-system too (via emulator).

Keep in mind however that such emulators are never perfect and thus it might be necessary nevertheless to test on a real system.

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

Graeme Geldenhuys-6
On 2016-09-01 19:02, Sven Barth wrote:
> Keep in mind however that such emulators are never perfect and thus it
> might be necessary nevertheless to test on a real system.

Linux support under FreeBSD is actually a full install of CentOS 6. So
in theory there should be issues testing a linux program under FreeBSD.
But yes, I still prefer actual VMs of each OS.

Regards,
  Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

Marc Santhoff-2
In reply to this post by fredvs
On Do, 2016-09-01 at 09:56 -0700, fredvs wrote:

> > With fpc's -k parameter, you can pass parameters directly to the linker.
> > If you need to pass multiple parameters, use -k several times
> > (e.g.-k-para1 -kvalue1)
>
> Wow, many thanks Jonas.
>
> I will try it and write you the result.
>
> But, imagine, with FreeBSD, you could:
> Compile and run on same system (no need virtual-box to test it):
> - FreeBSD 64 bit programs.
> - FreeBSD 32 bit programs.
> - Linux 64 bit programs.
> - Linux 32 bit programs.
> - Windows 64 bit programs (via wine).
> - Windows 32 bit programs (via wine).
> - Maybe other program-system too (via emulator).

See Greames message for why you still will have to use the Linux ld.
Your error message clearly says, the FreeBSD linker can only create bfsd
code for i386 and x64.

> Supported emulation: elf_x86_64_fbsd and elf_i386_fbsd

Have a look for brandelf(1), btw. You'll need it. And "man linux" will
tell some stories, too.

HTH,
Marc


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

Graeme Geldenhuys-6
In reply to this post by Graeme Geldenhuys-6
On 2016-09-01 19:53, Graeme Geldenhuys wrote:
> in theory there should be issues testing a linux program under FreeBSD.

Oops, typo. That should read: "..there should be no issues testing..."

Regards,
  Graeme

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

Graeme Geldenhuys-6
In reply to this post by Marc Santhoff-2
On 2016-09-01 20:28, Marc Santhoff wrote:
> See Greames message for why you still will have to use the Linux ld.

Yes, and when installed, it will most likely be installed in the
/compat/linux/* hierarchy.

Regards,
  Graeme

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

fredvs
In reply to this post by Marc Santhoff-2
> See Greames message for why you still will have to use the Linux ld.
> Your error message clearly says, the FreeBSD linker can only create bfsd
> code for i386 and x64.

>> Supported emulation: elf_x86_64_fbsd and elf_i386_fbsd

Yes, before to sent that topic, I have try with the Linux ld and...
in fact it is absolutely the same file than ld-freebsd. (same size, same date).

And using ld-linux gives the same message:

>> Supported emulation: elf_x86_64_fbsd and elf_i386_fbsd

So, maybe, (I do not know ld), like Jonas said, ld needs parameters to change default elf.
But yes, the best is to try it. And asap. I will try to find time tonight.

Many thanks.

Fre;D
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

fredvs
In reply to this post by Graeme Geldenhuys-6
> But yes, I still prefer actual VMs of each OS.

Me too if I had a powerful machine.
But on a slow netbook, the fotal-emulator of FreeBSD is a perfect solution.

Fre;D
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

Pierre Muller
In reply to this post by fredvs


> -----Message d'origine-----
> De : [hidden email] [mailto:fpc-pascal-
> [hidden email]] De la part de fredvs
> Envoyé : jeudi 1 septembre 2016 22:55
> À : [hidden email]
> Objet : Re: [fpc-pascal] Linking to Linux on a FreeBSD system with
> Linux emulated ?
>
> > See Greames message for why you still will have to use the Linux ld.
> > Your error message clearly says, the FreeBSD linker can only create
> bfsd
> > code for i386 and x64.
>
> >> Supported emulation: elf_x86_64_fbsd and elf_i386_fbsd
>
> Yes, before to sent that topic, I have try with the Linux ld and...
> in fact it is absolutely the same file than ld-freebsd. (same size,
> same
> date).
>
> And using ld-linux gives the same message:
>
> >> Supported emulation: elf_x86_64_fbsd and elf_i386_fbsd
>
> So, maybe, (I do not know *ld*), like Jonas said, *ld *needs parameters
> to
> change default elf.
> But yes, the best is to try it. And asap. I will try to find time
> tonight.

  What you need here is a multi-target linker,
you can get getting the GNU binutils sources
and running configure with the options:
  --enable-targets=all
combined with a second option to also enabled 64-bit targets
needed only if you are compiling on a 32-bit target which is:
--enable-64-bit-bfd

Pierre
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

Marc Santhoff-2
In reply to this post by fredvs
On Do, 2016-09-01 at 13:54 -0700, fredvs wrote:

> > See Greames message for why you still will have to use the Linux ld.
> > Your error message clearly says, the FreeBSD linker can only create bfsd
> > code for i386 and x64.
>
> >> Supported emulation: elf_x86_64_fbsd and elf_i386_fbsd
>
> Yes, before to sent that topic, I have try with the Linux ld and...
> in fact it is absolutely the same file than ld-freebsd. (same size, same
> date).
>
> And using ld-linux gives the same message:
>
> >> Supported emulation: elf_x86_64_fbsd and elf_i386_fbsd
>
> So, maybe, (I do not know *ld*), like Jonas said, *ld *needs parameters to
> change default elf.
> But yes, the best is to try it. And asap. I will try to find time tonight.

Sorry, I can't help you much with that, ld-linux is not installed here
and I don't know which package it is from.

But many binaries are links to the original binary which, when started,
check under what name they were started and behave accordingly. So the
fact that it's the same binary does not mean it cannot do the job.

Try asking it what options in knows with --help or -h or whatever works.
And have a look at the man page with "man ld-linux".

If all that gives not enough hints you could go to www.freebsd.org and
look in the at the documentation. The handbook and maybe the developers
handbook or FAQ may help.

HTH somehow,
Marc


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

fredvs
In reply to this post by Pierre Muller
Hello Pierre.

I will try first with Jonas tip.

If I m not able to do it work, i will try with binutils.

Many thanks to help.

Fre;D
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

fredvs
In reply to this post by Marc Santhoff-2
> Sorry, I can't help you much with that, ld-linux is not installed here
> and I don't know which package it is from.

Huh, is it possible to install Linux packages (apt-get install something) in a FreeBSD system ?
Or do you mean (like I did), copy ld-linux from a installed Linux system. ?

Thanks.

Fre;D
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

Marc Santhoff-2
On Do, 2016-09-01 at 14:24 -0700, fredvs wrote:
> > Sorry, I can't help you much with that, ld-linux is not installed here
> > and I don't know which package it is from.
>
> Huh, is it possible to install Linux packages (apt-get install something) in
> a FreeBSD system ?
> Or do you mean (like I did), copy ld-linux from a installed Linux system. ?

Sorry for being terse. A package in this context is a pre-compiled
binary port on FreeBSD. So I should have written "which FreeBSD
package".

For relevant ports see there:

https://www.freebsd.org/ports/linux.html

Most of those are installable without compiling by using pkg(1).

<https://www.freebsd.org/cgi/man.cgi?query=pkg&apropos=0&sektion=0&manpath=FreeBSD+10.3-RELEASE+and+Ports&arch=default&format=html>


Marc


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

fredvs
Hello.

The night was very long and hard...

I have some result.

Here how I did:

- Copy ld-linux into /compat/linux/bin

- Copy dependencies-linux needed by ld-linux (some needed to be in /compat/linux/lib, other in /compat/linux/lib64).

- When using fpc-linux to compile-link a simple fpgui-programe, compilation is ok, linking begin but after 3 minutes, there is a message from fpc.

> Error (9014) Can't call the linker, switching to external linking
> Error (9013) Error while linking.

So i tried to link manually all the compiled files in /units to see what appends with:

 ->  /compat/linux/bin/ld -o  /compat/linux/lib/crt0.o /usr/test/units/test.o -lc

And there is that error message:



Do you have a idea what is wrong ?

Many thanks.

Fre;D



Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

fredvs
In reply to this post by Marc Santhoff-2
Hello Marc.

Thanks for the infos, good to know that it is possible to install linux package via FreeBSD-pkg install.
Sadly I did not see any linux-ld or linux-binutils package in https://www.freebsd.org/ports/linux.html

So, the manually way that i did is the only way (yes/no ?).

Many thanks for your infos.

Fre;D
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

Marc Santhoff-2
In reply to this post by fredvs
On Fr, 2016-09-02 at 08:57 -0700, fredvs wrote:

> Hello.
>
> The night was very long and hard...
>
> I have some result.
>
> Here how I did:
>
> - Copy ld-linux into /compat/linux/bin
>
> - Copy dependencies-linux needed by ld-linux (some needed to be in
> /compat/linux/lib, other in /compat/linux/lib64).
>
> - When using fpc-linux to compile-link a simple fpgui-programe, compilation
> is ok, linking begin but after 3 minutes, there is a message from fpc.
>
> > Error (9014) Can't call the linker, switching to external linking
> > Error (9013) Error while linking.
>
> So i tried to link manually all the compiled files in /units to see what
> appends with:
>
>  ->  /compat/linux/bin/ld -o  /compat/linux/lib/crt0.o
> /usr/test/units/test.o -lc
>
> And there is that error message:
>
> <http://free-pascal-general.1045716.n5.nabble.com/file/n5726229/crossfbsdlin.jpg>
>
> Do you have a idea what is wrong ?

Not very precise, but the error "undefinded reference to ..." tells you
it can't find something, that should be there. And since $FPG_MAIN is
the first I assume you will have to pass a list of paths to ld helping
it finding the .o files missing.

There are ways to see the path list the compiler hands over to the
linker - which others will have to show you because I don't know how -
and then you can use that path list to tell the linker while trying
manually.


Marc


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

Marc Santhoff-2
In reply to this post by fredvs
On Fr, 2016-09-02 at 09:32 -0700, fredvs wrote:
> Hello Marc.

Hi Fred.

> Thanks for the infos, good to know that it is possible to install linux
> package via FreeBSD-pkg install.
> Sadly I did not see any linux-ld or linux-binutils package in
> https://www.freebsd.org/ports/linux.html
>
> So, the manually way that i did is the only way (yes/no ?).

Were reaching the end of my wisdom here. ;)

I know linux programs can be compiled on FreeBSD, but I do not know the
details. I'd suggest asking on one of the freebsd mailing lists or some
forum. You find them via the main page of the web site of freebsd in the
"community" menu.

Good luck,
Marc


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Linking to Linux on a FreeBSD system with Linux emulated ?

fredvs
In reply to this post by Marc Santhoff-2
Hello Marc.

And thanks to help.

OK, I have investigate more and there is something that disturb me:

When compiling on a FreeBSD 64 bit system using fpc-freebsd-64, there is that message on linking:

[3.069] Searching file /usr/bin/ld... found
[3.069] Using util /usr/bin/ld
[3.069] Executing "/usr/bin/ld -b elf64-x86-64-freebsd -m elf64-x86-64_fbsd -L. -o ./test ./link.res" with fpSystem call
[3.960] 62 lines compiled, 4.0 sec
[3.972] 2 hint(s) issued

OK, it works.

When compiling on a FreeBSD 64 bit system using fpc-freebsd-32 there is that message on linking:

[3.069] Searching file /usr/bin/ld... found
[3.069] Using util /usr/bin/ld
[3.069] Executing "/usr/bin/ld -b elf32-i386-freebsd -m elf32-i386-freebsd -L. -o ./test ./link.res" with fpSystem call
[3.960] 62 lines compiled, 4.0 sec
[3.972] 2 hint(s) issued

OK, it works.

When compiling on a FreeBSD 64 bit system using fpc-freebsd-32, there is that message on  linking:

3.069] Searching file /usr/bin/ld... found
[3.069] Using util /usr/bin/ld
[3.069] Executing "/usr/bin/ld -b elf32-i386-freebsd -m elf_i386_fbsd  -L. -o ./test ./link.res" with fpSystem call
[3.960] 62 lines compiled, 6.0 sec
[3.972] 2 hint(s) issued

OK, it works.

But when compiling on a FreeBSD 64 bit system using fpc-linux-64, there is that message on  linking:

[4.438] Searching file /bin/ld... found
[4.438] Using util /bin/ld
[4.438] Executing "/bin/ld" with command line "-b elf64-x86-64 -m elf_x86_64  --dynamic-linker=/lib64/ld-linux-x86-64.so
.2
  -L. -o ./test ./link.res"
/bin/ld: warning: ./link.res contains output sections; did you forget -T?
[246.930] test.pas(62,1) Error: Can't call the linker, switching to external linking
[246.930] test.pas(62,1) Error: Error while linking
[246.930] test.pas(62,1) Fatal: There were 2 errors compiling module, stopping
[247.070] Fatal: Compilation aborted

So the question is:
What define in fpc.cfg --->
with fpSystem call 
vs
--dynamic-linker=/lib64/ld-linux-x86-64.so.2 

This because I want to try when linking using fpc-linux:

[4.438] Executing "/bin/ld" with command line "-b elf64-x86-64 -m elf_x86_64  with fpSystem call   -L. -o ./test ./link.res"

Many thanks.

Fre;D
Many thanks ;-)
12