2011-04-20 09:08:30     [2010R1-RC5] lsof doesn't compile

Document created by Aaronwu Employee on Aug 26, 2013
Version 1Show Document
  • View in full screen mode

2011-04-20 09:08:30     [2010R1-RC5] lsof doesn't compile

Gilles Ganault (FRANCE)

Message: 100042   

 

Hello

 

I tried compiling a new image to include lsof so I can find which application is using a port, but regardless of using uClibc-default or uClibc-full 2010R1-RC4, compiling fails:

 

=========

 

bfin-uclinux-gcc -o lsof dfile.o dmnt.o dnode.o dproc.o dsock.o dstore.o arg.o main.o misc.o node.o print.o proc.o store.o usage.o -L./lib -llsof

misc.o: In function `doinchild':

/usr/src/uClinux-dist-2010R1-RC5/user/lsof/lsof/misc.c:286: undefined reference to `_fork'

collect2: ld returned 1 exit status

make[6]: *** [lsof] Error 1

make[6]: Leaving directory `/usr/src/uClinux-dist-2010R1-RC5/user/lsof/lsof'

make[5]: *** [all] Error 2

make[5]: Leaving directory `/usr/src/uClinux-dist-2010R1-RC5/user/lsof'

make[4]: *** [lsof] Error 2

make[4]: Leaving directory `/usr/src/uClinux-dist-2010R1-RC5/user'

make[3]: *** [all] Error 2

make[3]: Leaving directory `/usr/src/uClinux-dist-2010R1-RC5/user'

make[2]: *** [subdirs] Error 1

make[2]: Leaving directory `/usr/src/uClinux-dist-2010R1-RC5'

make[1]: *** [single_] Error 2

make[1]: Leaving directory `/usr/src/uClinux-dist-2010R1-RC5'

make: *** [single] Error 2

 

=========

Since lsof is part of uClinux-dist, I guess it used to compile with older toolchains but wasn't removed to comply with newer ones. Is there an alternative within uClinux-dist that I could use instead?

 

Thank you.

 

QuoteReplyEditDelete

 

 

2011-04-20 09:16:23     Re: [2010R1-RC5] lsof doesn't compile

Gilles Ganault (FRANCE)

Message: 100043   

 

In case someone else needs the same thing:  "netstat -natp" displays the name of the program that opened the port.

QuoteReplyEditDelete

 

 

2011-04-20 10:11:54     Re: [2010R1-RC5] lsof doesn't compile

Robert Wimmer (GERMANY)

Message: 100044   

 

> "netstat -natp" displays the name of the program that opened the port.

 

Thx for the useful info!

 

 

 

About your problem: I do not have a solution. I'm just a little bit curious.

 

Which Blackfin architecture are you using? There are some, like BF-53x, that don't have an MMU so forking is not possible (look out for vfork in the sources instead).

 

Which board?

 

Do you find any NOMMU option active in any of your uClinux (userland, kernel) configurations?

TranslateQuoteReplyEditDelete

 

 

2011-04-20 15:19:50     Re: [2010R1-RC5] lsof doesn't compile

Mike Frysinger (UNITED STATES)

Message: 100047   

 

just change it to vfork() ... the child only reads/writes fd's, so it should be safe

QuoteReplyEditDelete

 

 

2011-04-22 07:36:41     Re: [2010R1-RC5] lsof doesn't compile

Gilles Ganault (FRANCE)

Message: 100128   

 

just change it to vfork() ... the child only reads/writes fd's, so it should be safe

 

---

 

Thanks, that did it:

 

//if ((Cpid = fork()) == 0) {

 

if ((Cpid = vfork()) == 0) {

 

 

BTW, I notice that lsof is compiled as FLAT:

 

/usr/src/uClinux-dist-2010R1-RC5# file user/lsof/lsof/lsof

user/lsof/lsof/lsof: BFLT executable - version 4 ram

 

Am I correct in understanding that it's better to use FLAT for stand-alone applications, and use FDPIC ELF for applications that depend on shared libraries?

 

https://docs.blackfin.uclinux.org/doku.php?id=toolchain:executable_file_formats

QuoteReplyEditDelete

 

 

2011-04-22 08:38:08     Re: [2010R1-RC5] lsof doesn't compile

Gilles Ganault (FRANCE)

Message: 100129   

 

Apparently, it's not just a matter of changin fork to vfork:

 

/var/tmp> ./lsof -Pnl +M -i4

 

SEGV

QuoteReplyEditDelete

 

 

2011-04-26 09:59:47     Re: [2010R1-RC5] lsof doesn't compile

Robert Wimmer (GERMANY)

Message: 100172   

 

Hmmm, have you ensured that your kernel is able to run FLAT binaries?

 

Look out for this in the kernel configuration:

 

 

 

Executable file formats

 

-> [X] Kernel support for flat binaries

 

 

 

As I understood, FLAT binaries are a little bit smaller while FDPIC ones are more dynamic in general.

TranslateQuoteReplyEditDelete

 

 

2011-04-26 13:34:52     Re: [2010R1-RC5] lsof doesn't compile

Gilles Ganault (FRANCE)

Message: 100177   

 

Thanks Robert, but it looks OK:

 

=================

 

[*] Kernel support for FDPIC ELF binaries

 

[*] Kernel support for flat binaries

 

[ ]   Enable ZFLAT support

 

[ ]   Enable shared FLAT support

 

< > Kernel support for MISC binaries

 

=================

 

file lsof: BFLT executable - version 4 ram

 

=================

 

Is there a way to make sure lsof doesn't rely on shared libraries?

QuoteReplyEditDelete

 

 

2011-04-27 04:08:08     Re: [2010R1-RC5] lsof doesn't compile

Robert Wimmer (GERMANY)

Message: 100196   

 

Ok, that's bad... I cannot reproduce your problem. I didn't even have to edit the sources of "lsof".

 

PC:

 

2010R1-RC5> head -n2 user/lsof/RELEASE.SUMMARY_4.78

                    lsof (LiSt Open Files) version 4

                            (revision 4.78)

 

2010R1-RC5> file romfs/bin/lsof

romfs/bin/lsof: ELF 32-bit LSB executable, Analog Devices Blackfin, version 1 (SYSV), dynamically linked (uses shared libs), stripped

 

2010R1-RC5> bfin-linux-uclibc-ldd romfs/bin/lsof

ldd: can't map cache '/etc/ld.so.cache'

checking sub-depends for '/lib/libgcc_s.so.1'

checking sub-depends for 'not found'

checking sub-depends for '/lib/libc.so.6'

        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00000000)

        libc.so.0 => not found (0x00000000)

        libc.so.6 => /lib/libc.so.6 (0x00000000)

        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00000000)

 

uClinux:

 

root:~> lsof

lsof: can't fork: Function not implemented

root:~> lsof -Pnl +M -i4

COMMAND PID     USER   FD   TYPE DEVICE SIZE NODE NAME

inetd   353        0    4u  inet   1321       TCP *:22 (LISTEN)

 

 

 

The main difference is that I use FDPICs only:

 

Kernel configuration:

 

================

 

[*] Kernel support for FDPIC ELF binaries

 

[ ] Kernel support for flat binaries

 

< > Kernel support for MISC binaries

 

 

 

User configuration:

 

===============

 

Blackfin build options

 

Binary format (FDPIC)  --->

  ( ) FLAT

  ( ) Sep-Data

  ( ) Shared-FLAT

  (X) FDPIC

--- Install ELF shared libraries

[*]   Cull unused ELF shared libraries

[ ] Install FLAT shared libraries

(-g -O2) User/Lib CFLAGS

[ ] build with stack overflow checking

[ ] build with mudflap pointer checking

[*] install uClinux-dist .config into /root

[*] use ccache to speed up builds

 

> Is there a way to make sure lsof doesn't rely on shared libraries?

 

Don't know that. Manipulating Makefiles? But I think there's not really a need for that. I could imagine that setting the Binary format would be your key to success.

TranslateQuoteReplyEditDelete

 

 

2011-04-27 06:25:25     Re: [2010R1-RC5] lsof doesn't compile

Gilles Ganault (FRANCE)

Message: 100200   

 

Thanks Robert. As a work-around, I'll disable FLAT to force compiling applications as FDPIC ELF.

QuoteReplyEditDelete

 

 

2011-04-27 15:36:42     Re: [2010R1-RC5] lsof doesn't compile

Robert Wimmer (GERMANY)

Message: 100213   

 

You're welcome!

 

But keep in mind that you also have to set Userland configuration:

 

Blackfin build options

Binary format (FDPIC)  --->

  ( ) FLAT

  ( ) Sep-Data

  ( ) Shared-FLAT

  (X) FDPIC

 

Perhaps it is sufficient to set application's binary format to

 

Blackfin build options

Binary format (FDPIC)  --->

  ( ) FLAT

  ( ) Sep-Data

  (X) Shared-FLAT

  ( ) FDPIC

 

Haven't tried that, but... who knows.

 

Good luck and have fun!

TranslateQuoteReplyEditDelete

 

 

2011-04-27 18:48:04     Re: [2010R1-RC5] lsof doesn't compile

Mike Frysinger (UNITED STATES)

Message: 100214   

 

FLAT vs FDPIC shouldnt matter.  what might be an issue is the default stack in FLAT is quite small.  you might want to try increasing it with bfin-uclinux-flthdr and see if it runs any better.

QuoteReplyEditDelete

 

 

2011-04-28 04:40:43     Re: [2010R1-RC5] lsof doesn't compile

Gilles Ganault (FRANCE)

Message: 100244   

 

Thanks for the tip. By default, the stack is 0x1000 (4096). After doubling its size thusly...

 

==============

 

bfin-uclinux-flthdr -s 8192 user/lsof/lsof/lsof

 

==============

 

 

 

... I gave it another try, and this time, I get a different error:

 

==============

 

> ./lsof -Pnl +M -i4

 

BUS

 

==============

 

 

Generally speaking, is there a document on the wiki that gives the list of possible errors returned by uClinux when running a binary?

QuoteReplyEditDelete

 

 

2011-04-28 06:38:13     Re: [2010R1-RC5] lsof doesn't compile

Mike Frysinger (UNITED STATES)

Message: 100248   

 

8K is still awfully small.  FDPIC uses 0x20000 by default.

 

as for the error, read `dmesg`.

QuoteReplyEditDelete

 

 

2011-04-28 09:01:11     Re: [2010R1-RC5] lsof doesn't compile

Gilles Ganault (FRANCE)

Message: 100263   

 

Thanks. Changing the stack to 0x20000 worked:

 

/var/tmp> ./lsof -Pnl +M -i4

 

COMMAND   PID     USER   FD   TYPE DEVICE SIZE NODE NAME

 

inetd     314        0    4u  inet   5437       TCP *:22 (LISTEN)

 

dropbear 1858        0    0u  inet   5601       TCP 192.168.0.9:22->192.168.0.1:54772 (ESTABLISHED)

 

There's no error in dmesg, however. Is there a list of errors that can be returned by a FLAT file (and an FDPIC ELF, as well) and their meaning, eg. SEGV, BUS, etc.?

QuoteReplyEditDelete

 

 

2011-04-28 09:10:26     Re: [2010R1-RC5] lsof doesn't compile

Mike Frysinger (UNITED STATES)

Message: 100264   

 

those arent "returned errors".  those are signals sent by the kernel when the app did something wrong and the app did not catch them which means it was killed.  if there's no trace in `dmesg`, it sounds like you disabled the debug options which would prented out the failing info.

QuoteReplyEditDelete

 

 

2011-04-28 18:30:21     Re: [2010R1-RC5] lsof doesn't compile

Gilles Ganault (FRANCE)

Message: 100271   

 

those arent "returned errors".  those are signals sent by the kernel when the app did something wrong and the app did not catch them which means it was killed.  if there's no trace in `dmesg`, it sounds like you disabled the debug options which would prented out the failing info.

 

---

 

No, I didn't. I used the defaults and simply ran "make" to build a new image. How do I enable debugging?

 

The following document in the wiki explains how to customize Makefiles to enable debugging, but I'd rather not have to do this and simply enable debugging at the general level:

 

  docs.blackfin.uclinux.org/doku.php?id=uclinux-dist:debugging_applications

QuoteReplyEditDelete

 

 

2011-04-29 01:28:42     Re: [2010R1-RC5] lsof doesn't compile

Mike Frysinger (UNITED STATES)

Message: 100275   

 

all ADI defconfigs enable debugging options such that a crash (something that'd send a SIGV or BUS) would result in trace.  please go into the kernel debugging menu to see it.

Attachments

    Outcomes