Bug 12815 - Segmentation fault when using a global variable, a special linker script and emulation elf64mmix
Summary: Segmentation fault when using a global variable, a special linker script and ...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.21
: P2 normal
Target Milestone: ---
Assignee: Hans-Peter Nilsson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-27 08:44 UTC by Nils Asmussen
Modified: 2011-07-25 01:23 UTC (History)
2 users (show)

See Also:
Host: Ubuntu on x86_64
Target: MMIX
Build: gcc-4.6.0 with binutils-2.21
Last reconfirmed:


Attachments
Object file, that causes the error (243 bytes, application/octet-stream)
2011-05-27 15:42 UTC, Nils Asmussen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nils Asmussen 2011-05-27 08:44:38 UTC
I've build a cross-compiler with gcc-4.6.0 and binutils-2.21 for MMIX. There seems to be a problem with the emulation elf64mmix.

To reproduce the problem, use the following c-file:
----
static unsigned int foo = 2;
int main(void) {
	foo++;
	return 0;
}
----
And the following linker-script:
----
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
	. = 0x8000000000100000;
	.text : AT(ADDR(.text) - 0x8000000000100000)
	{
		*(.text)
		*(.data)
		*(.rodata*)
		*(COMMON*)
		*(.bss*)
	}
}
----

Compiling the c-file and linking it via:
$ mmix-elf-escape-gcc -o test.o -c test.c
$ mmix-elf-escape-ld -m elf64mmix -o test test.o -T ld.conf -nostdlib

produces:
Segmentation fault
Comment 1 Nils Asmussen 2011-05-27 09:03:03 UTC
After playing around a bit with the linker-script, I've found out, that the only problem seems to be that I would like to have OUTPUT_FORMAT "binary" instead of "elf64-mmix". As soon as I use "elf64-mmix", it works.
Comment 2 Hans-Peter Nilsson 2011-05-27 14:40:03 UTC
Can you please attach test.o, the object file?  Thanks.

While it's definitely a bug that the linker segfaults, generating a "binary" file is generally better done using objcopy.
Comment 3 Nils Asmussen 2011-05-27 15:42:28 UTC
Created attachment 5758 [details]
Object file, that causes the error
Comment 4 Hans-Peter Nilsson 2011-05-28 23:43:42 UTC
Ok, repeated.
Comment 5 cvs-commit@gcc.gnu.org 2011-07-25 01:14:23 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	hp@sourceware.org	2011-07-25 01:14:20

Modified files:
	bfd            : ChangeLog elf64-mmix.c 

Log message:
	PR ld/12815
	* elf64-mmix.c (struct _mmix_elf_section_data): New members
	has_warned_bpo and has_warned_pushj.
	(mmix_final_link_relocate): Remove PARAMS and PTR macros,
	converting to ISO C.  Add new parameter error_message.  All
	callers changed.
	(mmix_elf_perform_relocation): Ditto.
	<case R_MMIX_PUSHJ_STUBBABLE, case R_MMIX_BASE_PLUS_OFFSET>:
	Handle the case where mmix_elf_check_common_relocs has not been
	called, missing preparations for relocs of the respective type.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5429&r2=1.5430
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf64-mmix.c.diff?cvsroot=src&r1=1.63&r2=1.64
Comment 7 Hans-Peter Nilsson 2011-07-25 01:23:47 UTC
Will instead error gracefully starting with binutils-2.22.
See <http://sourceware.org/ml/binutils/2011-07/msg00199.html>.
If the error message isn't helpful enough, please suggest improvements here or on the list.  Thanks for the report.