When compiling the binutils on some systems, the ld link fails. The reason is that the generated emulation C file is empty. By looking at the make output, we can see .../genscripts.sh: line 403: ${BASH_LINENO[0]} + 1: bad substitution However, no error is detected, and the build process of ld continues until the final link, which fails. This happens when $(SHELL) is actually bash compiled with the --enable-minimal- config option. In that case, the variable BASH is set, but the array BASH_LINENO is not supported. The problem is at the bottom of ld/genscripts.sh If it is supported by the shell, line number information is inserted into the generated emulation source, by using BASH_LINENO. However the detection method is wrong. It assumes that if the BASH variable is set, the BASH_LINENO array will be available, which is not always true.
Created attachment 2208 [details] genscripts fix This patch fixes the bug. The availability of the BASH_LINENO variable is now checked in a reliable way.
Hi Vincent, Thanks for reporting this problem. I am not sure if your proposed patch will work for all versions of /bin/sh however. Correct me if I am wrong, but aren't shell functions a feature of bash rather than all shells ? So wouldn't it be better to just test BASH_LINENO directly ? eg: if test $BASH_LINENO" != "x"; then source_em() Cheers Nick
http://www.faqs.org/faqs/unix-faq/shell/shell-differences/ sh csh ksh bash tcsh zsh rc es Shell functions Y(1) N Y Y N Y Y Y 1. This feature was not in the orginal version, but has since become almost standard.
Furthermore: - SVR2 (1984): - shell functions (sh) http://www.faqs.org/faqs/unix-faq/faq/part6/ I didn't find any documentation about POSIX. But bash --posix knows about functions. And dash (ash) knows it, too (without the function keyword). I really think this patch is good and harmless. I put the test in a function because the BASH_LINENO (a bash builtin) exists only in functions ! And as the original code uses functions, it doesn't matter to add one more. The original code uses the BASH_LINENO trick in order to produce #line statements about the original em file into the generated C file. If BASH_LINENO is available, the script use it. If not, it does not produce #line. The BASH_LINENO trick is absolutely not mandatory. It just helps to get better error report when there is a compilation problem in the em file. Regards, Vincent
Sorry, there is a typo in the comments: accruate instead of accurate
Hi Vincent, Ok, I am convinved. I have checked your patch in along with this changelog entry. Cheers Nick ld/ChangeLog 2008-01-28 Vincent Riviere <vincent.riviere@freesbee.fr> PR ld/5652 * genscripts.sh: Check for the existence of BASH_LINENO not just the BASH shell before generating line numbers in the emulation file.