Bug 214440

Summary: unaligned access in ld.so when linking dmraid
Product: Red Hat Enterprise Linux 5 Reporter: Bryn M. Reeves <bmr>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED WONTFIX QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 5.0CC: drepper
Target Milestone: ---   
Target Release: ---   
Hardware: ia64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-11-07 22:03:57 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
patch to work around unaligned accesses in ld none

Description Bryn M. Reeves 2006-11-07 17:42:54 UTC
Split off from bug 202096 (ia64: unaligned accesses during dmraid execution at
startup)

ld generates unaligned access faults on ia64 linking dmraid.so to dmraid.

The faulting instruction lies in _dl_relocate_object:

dmraid(4716): unaligned access to 0x20000000000ae0be, ip=0x2000000000018080

Breakpoint 2, 0x2000000000018090 in _dl_relocate_object () from
/lib/ld-linux-ia64.so.2
(gdb) bt
#0  0x2000000000018090 in _dl_relocate_object () from /lib/ld-linux-ia64.so.2
#1  0x2000000000008450 in dl_main () from /lib/ld-linux-ia64.so.2
#2  0x200000000002c5e0 in _dl_sysdep_start () from /lib/ld-linux-ia64.so.2
#3  0x2000000000004bf0 in _dl_start () from /lib/ld-linux-ia64.so.2
#4  0x2000000000001590 in _start () from /lib/ld-linux-ia64.so.2

Intel further pinned this down to:

sysdeps/ia64/dl-machine.h.

elf_machine_rela_relative (Elf64_Addr l_addr, const Elf64_Rela *reloc,
                           void *const reloc_addr_arg)
{
  Elf64_Addr *const reloc_addr = reloc_addr_arg;
  /* ??? Ignore MSB and Instruction format for now.  */
  assert (ELF64_R_TYPE (reloc->r_info) == R_IA64_REL64LSB);

  *reloc_addr += l_addr; <--------
}

It sems like the faults happen relocating an array of packed structs:

struct format_member {
        const unsigned short offset;
        const unsigned char flags;
        const char *msg;
} __attribute__ ((packed));

static struct format_member format_member[] = {
        ...
};

A patch was pasted into bug 202096 that makes _dl_relocate_object check for
unaligned accesses and work around them - will attach here also.

Comment 1 Bryn M. Reeves 2006-11-07 17:48:53 UTC
The RHEL5 version of the dmraid issue is in bug 211150

Comment 2 Jakub Jelinek 2006-11-07 17:49:56 UTC
I think there is no way we want to slow down the dynamic linker to workaround
buggy apps.  An array of packed struct requiring runtime relocations is simply
a big no no.

Comment 3 Bryn M. Reeves 2006-11-07 17:58:04 UTC
Created attachment 140576 [details]
patch to work around unaligned accesses in ld

Comment 4 Jakub Jelinek 2006-11-07 22:03:57 UTC
Unaligned relocations are extremely rare and the kernel has unaligned trap
handler which handles it just fine.
So, IMHO:
1) dmraid needs to be fixed not to have unaligned relocations
2) kernel should at least rate limit the unaligned trap messages if it is not
doing that
On IA-64 prelink isn't supported and for larger libraries
elf_machine_rela_relative inline is called really many times (e.g. libgcj.so.7rh
alone has 347305 relative relocations), adding a conditional jump there will
show up quite measurably.  Furthermore, there isn't anything special on relative
relocations, so we'd need change all other non-instruction relocations too.
It is much better to leave the very rare case to the unaligned trap handler and
attempt that at least in the libraries we ship unaligned relocations aren't
used or used very rarely.