Subject: R_68K_32 relocation with addend on ld.elf_so
To: None <port-m68k@netbsd.org, tech-toolchain@netbsd.org>
From: ITOH Yasufumi <itohy@netbsd.org>
List: tech-toolchain
Date: 10/19/1999 12:00:06
Dear elf guru,

I need the change below to ld.elf_so
to get correct relocation of __sF (in lib/libc/stdio/findfp.c)
on m68k ELF.

    % objdump --dynamic-reloc libc.so.12.49 | grep '__sF+'
    00067f80 R_68K_32          __sF+0x00000058
    00067fd8 R_68K_32          __sF+0x000000b0

    % cat foo.c			# Here is a test program.
    #include <stdio.h>
    main()
    {
	    printf("%p %p\n", stdout, stdout->_cookie);
    }
    % cc foo.c
    % ./a.out			# execute with current ld.elf_so
    0x800029f0 0x80002998	# wrong!  The values should be identical.

The addends (0x58 and 0xb0 in this example) to the symbols are
in r_addend element of the relocation structure,
not in the *where positions.

Is this change correct?  Or am I breaking something?
--
ITOH, Yasufumi <itohy@netbsd.org>


diff -uF^[a-zA-Z_][a-z 	A-Z0-9_]*(.*[^;]$ libexec/ld.elf_so/reloc.c.orig libexec/ld.elf_so/reloc.c
--- libexec/ld.elf_so/reloc.c.orig	Mon Aug 23 14:07:24 1999
+++ libexec/ld.elf_so/reloc.c	Tue Oct 19 01:16:03 1999
@@ -212,7 +212,8 @@ _rtld_relocate_nonplt_object(obj, rela, 
 		if (def == NULL)
 			return -1;
 
-		*where += (Elf_Addr)(defobj->relocbase + def->st_value);
+		*where = (Elf_Addr)(defobj->relocbase + def->st_value +
+		    rela->r_addend);
 		rdbg(dodebug, ("32 %s in %s --> %p in %s",
 		    defobj->strtab + def->st_name, obj->path,
 		    (void *)*where, defobj->path));