3

I've compiled an Ada program for Linux on Ubuntu 5.4 (GNAT 3.4) using the following command:

gnatmake -O3 myprogram -bargs -static

When I run the program on the Ubuntu machine then, it works fine. But on another machine (Linux webserver), I get the following error message when I try strace:

execve("./myprogram", ["./myprogram"], [/* 15 vars */]) = 0
brk(0)                                  = 0x811e000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb76f8000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb76f7000
set_thread_area({entry_number:-1 -> 6, base_addr:0xb76f7680, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++

What does that mean? Do I understand it correctly that the program is unable to run because two files (ld.so.nohwcap and ld.so.preload) are missing? How can I avoid this error? Is there any possibility to include these files into the program while compiling?

caw
  • 30,999
  • 61
  • 181
  • 291
  • 1
    The output you see doesn't necessarily - indeed probably doesn't - mean there's a connection between the segv and the missing files. You'll see that sort of thing all the time in strace; it's just the system looking for e.g. a preload library which might or might not be there. gdb is a better tool for tracking down segvs, if you have debugging symbols in your program. It's a long time since I've debugged ADA, so I'm not sure exactly how to go about that. – jimw Apr 12 '12 at 00:19
  • Also, did you build the program on the webserver, or copy the binary over? If the latter, try building it there. – jimw Apr 12 '12 at 00:20
  • I copied the binary over. But this is necessary as GNAT is missing on the webserver. And I'm not allowed to install new packages there. – caw Apr 12 '12 at 10:22

3 Answers3

4

What does that mean?

It means that your program tried to dereference a NULL pointer and died with SIGSEGV

Do I understand it correctly that the program is unable to run because two files (ld.so.nohwcap and ld.so.preload) are missing?

No: it is perfectly normal for these files to not exist, and your problem has nothing to with them.

  1. The tool to debug problems like this is gdb. strace is only rarely useful for such debugging.
  2. Contrary to popular belief, fully-static executables (as the one you built) are less portable on Linux, then dynamically-linked ones. In particular, you probably got warnings at link time, similar to this one:

    Using 'initgroups' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

    If so, and if versions of glibc installed on your build and webserver machines are different, then that's precisely your problem. Don't ignore such warnings (and don't link your executables with -static flag).

Update:

Is it possible to include only the missing libgnat into the program?

It may be possible: what you want to do is arrange for the final link line to look like this:

gcc ... -Wl,-Bstatic -lgnat -Wl,-Bdynamic ...

I don't know how to achieve that with gnatmake.

Another, perhaps simpler, alternative: have you considered installing libgnat-3.4.so.1 on the server?

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • I didn't see this warning. But now I recompiled the program without the `-static` and `-bargs` flags. The `strace` output was longer and didn't contain the `SIGSEGV KILL` anymore. So it looked better. But when I checked the dependencies with `ldd` it said `linux-gate.so.1 => (0xffffe000) libgnat-3.4.so.1 => not found libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb786c000) libc.so.6 => /lib/libc.so.6 (0xb7726000) /lib/ld-linux.so.2 (0xb7893000)`. How can I fix this? Is it possible to include only the missing `libgnat` into the program? – caw Apr 12 '12 at 10:53
  • Thank you very much for the answer and the addition! Resolving the dependency is really important because this dependency is the only difference between the `ldd` output for my program and the pre-compiled one that works. So if I resole the dependency on libgnat, the program will (probably) run. – caw Apr 12 '12 at 16:48
  • I think I found the problem: I have `gnat-3.4` installed which depends on `gcc-3.4`. But I have not only `gcc-3.4` but also `gcc-4.0` on this system. So maybe the compiler uses the version 4.0 which is too new. Could that be the cause? – caw Apr 12 '12 at 17:23
  • And what about `gnatlink`? Isn't this to integrate a shared library into the compiled program? – caw Apr 12 '12 at 17:24
  • Finally solved the problem setting the `LD_LIBRARY_PATH` to a local directory and putting the missing dependency there. Thank you very much! – caw Apr 13 '12 at 00:17
2

The Output you see from strace is the dynamic linker trying to link in libraries

  1. I can recommend to you to run ldd this will show you the dependencies
  2. Fix the dependencies, if that doesn't work
  3. If you recompile it use the -g flag to later debug it
  4. If it's still not running use gdb and run it, if it quits with SIGSEV type in where

Side Note: Always make sure the CPU is "exactly" the same, otherwise recompile it on the new machine and that you transfer the executable as binary

The Man Page which is nice to be read

Oliver
  • 928
  • 9
  • 25
1

Also keep in mind that moving a program compiled on one Linux machine (Ubuntu 5.4) to another (the webserver) may have different file dependencies. Especially if they're based on different distros. Here is a description of the ld.so.* files: scroll to the bottom.

Try jimw's suggestion and build the program on the webserver. GNAT 3.4 is an older version, so it may not be available for use on the webserver. Also keep in mind, Employed Russian's advise - don't use the -static flag. You can try and recompile your program on Ubuntu without the -static flag and run the new version on the webserver, but this may not solve the error.

If the recompile and/or compiling it on the webserver doesn't work, you'll have to use gdb to debug your program. Or you can post part of the code here and see if someone can help you.

kmarcini
  • 37
  • 2
  • Thank you! Compiling the program without the `-static` flag helped. Finally, copying all missing dependencies and setting the `LD_LIBRARY_PATH` solved the rest of the problem. – caw Apr 13 '12 at 00:15