Ld-Linux -Verify Exit Codes

ld-linux --verify exit codes

I didn't find any documentation, but...

  if (__builtin_expect (mode, normal) == verify)
{
/* We were called just to verify that this is a dynamic
executable using us as the program interpreter. Exit with an
error if we were not able to load the binary or no interpreter
is specified (i.e., this is no dynamically linked binary. */
if (main_map->l_ld == NULL)
_exit (1);

/* We allow here some platform specific code. */
#ifdef DISTINGUISH_LIB_VERSIONS
DISTINGUISH_LIB_VERSIONS;
#endif
_exit (has_interp ? 0 : 2);
}

So...

  • 0 means success, i.e. "program is dynamically linked and this
    dynamic linker can handle it"
  • 1 means ld-linux was "not able to load the binary" (I got
    this when I ran ld-linux with non-existent, non-binary or static binary file)
  • 2 means "no interpreter is specified". More specifically, there is no element with p_type equal PT_INTERP in program header table (I get this when I run ld-linux with shared library)

There are no other codes.

Are there any standard exit status codes in Linux?

8 bits of the return code and 8 bits of the number of the killing signal are mixed into a single value on the return from wait(2) & co..

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>

int main() {
int status;

pid_t child = fork();
if (child <= 0)
exit(42);
waitpid(child, &status, 0);
if (WIFEXITED(status))
printf("first child exited with %u\n", WEXITSTATUS(status));
/* prints: "first child exited with 42" */

child = fork();
if (child <= 0)
kill(getpid(), SIGSEGV);
waitpid(child, &status, 0);
if (WIFSIGNALED(status))
printf("second child died with %u\n", WTERMSIG(status));
/* prints: "second child died with 11" */
}

How are you determining the exit status? Traditionally, the shell only stores an 8-bit return code, but sets the high bit if the process was abnormally terminated.


$ sh -c 'exit 42'; echo $?
42
$ sh -c 'kill -SEGV $$'; echo $?
Segmentation fault
139
$ expr 139 - 128
11

If you're seeing anything other than this, then the program probably has a SIGSEGV signal handler which then calls exit normally, so it isn't actually getting killed by the signal. (Programs can chose to handle any signals aside from SIGKILL and SIGSTOP.)

Check all commands exit code within a bash script

You can write a function that launches:

function test {
"$@"
local status=$?
if [ $status -ne 0 ]; then
echo "error with $1" >&2
fi
return $status
}

test command1
test command2

What does process exit status 3 mean?

At least in the old days, a return value of 1 generally meant a hard error and value 2 was usually reserved for problems with the command line arguments — it meant that the user had made an error, not the program. But beyond that: no, no convention; and even that slight convention was not universal. Like dashes in front of command-line arguments, which some versions of ps(1) let you omit, return codes were just convention. In general, read the docs (or the source!) to the script you're running and you then have to write error-code checking code to its specific meanings.

What are the return/exit codes for resize2fs?

Checking the source here. It looks like the only available exit codes are ENOMEM (12), 1 and 0. On a malloc() fail, on other errors, and on success, respectively.

Undocumented linker issue: ld returned 253 exit status

The reason for the error was that VLA's were used in the implementation of Libiberty. VLA's are data structures placed on the stack which, when a program has a large numbers of symbols, blows through the application's stack limit. In Libiberty there is a flag that permits avoiding VLA's, and the result is use of alloca. This allocation occurs on the stack, and the same issue occurs.

GCC 7.2 generates much more symbol information than GCC 8.2.

Solutions are threefold:

  1. On Linux, use ulimit -s unlimited and launch GCC 7.2 from the same terminal window. ulimit only affects child processes.
  2. On Windows, recompile GCC ld.exe with a different stack size for Windows. editbin didn't work correctly on ld.exe.
  3. Windows/Linux: upgrade to GCC 8.2. This version of the compiler is much better with symbols, and the issue resolves itself in this scenario.

The issue has been raised with Libiberty by Tamar Christina, and I suspect that, just like the Linux kernel, VLA's will be removed from the implementation.

127 Return code from $?

Value 127 is returned by /bin/sh when the given command is not found within your PATH system variable and it is not a built-in shell command. In other words, the system doesn't understand your command, because it doesn't know where to find the binary you're trying to call.

How to get the exit code of spawned process in expect shell script?

With the help of glenn, I got solution.. and my final script is::

expect script is

 [Linux Dev:anr ]$ cat testexit.sh
#!/bin/bash
export tmp_script_file="/home/anr/tmp_script_temp.sh"
cp /home/anr/tmp_script $tmp_script_file
chmod a+x $tmp_script_file
cat $tmp_script_file
expect << 'EOF'
set timeout -1
spawn $env(tmp_script_file)
expect {
"INVALID " { exit 4 }
timeout { exit 4 }
eof
}

foreach {pid spawnid os_error_flag value} [wait] break

if {$os_error_flag == 0} {
puts "exit status: $value"
exit $value
} else {
puts "errno: $value"
exit $value
}
EOF
echo "spawned process status" $?
rm -f $tmp_script_file
echo "done"

Spawned script:

 [Linux Dev:anr ]$ cat tmp_script
exit 3

Execution of Expect script:

 [Linux Dev:anr ]$ ./testexit.sh
exit 3
spawn /home/anr/tmp_script_temp.sh
exit status: 3
spawned process status 3
done

Thanks Glenn once again..

Check the output of make and exit bash script if it fails

Just check the exit code of make:

cmake . || exit 1
make || exit 1
./pcl_visualizer_demo


Related Topics



Leave a reply



Submit