Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 9 Jan 2011 00:23:36 GMT
From:      Gleb Kurtsou <gleb.kurtsou@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/153801: [patch] btxld produces incorrect ELF binaries
Message-ID:  <201101090023.p090NaTe096165@red.freebsd.org>
Resent-Message-ID: <201101090030.p090U52T000439@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         153801
>Category:       bin
>Synopsis:       [patch] btxld produces incorrect ELF binaries
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jan 09 00:30:05 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Gleb Kurtsou
>Release:        
>Organization:
>Environment:
FreeBSD 9.0-CURRENT #11 r216922+3950ba5
>Description:
ELF binaries linked by btxld have invalid .data section virtual address.

In a.out binaries .data section is aligned at page size, but it's not the case with ELF. btxldr expects kernel to be on next page (.data section):

see sys/boot/i386/btx/btxldr.S:

 .set MEM_DATA,start+0x1000      # Data segment

With the patch applied resulted binaries can be booted by grub (as well as a.out binaries). I didn't check if booting ELF loader is supported by FreeBSD boot2 code.
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

diff --git a/usr.sbin/btxld/btxld.c b/usr.sbin/btxld/btxld.c
index 1102b5c..7984c4c 100644
--- a/usr.sbin/btxld/btxld.c
+++ b/usr.sbin/btxld/btxld.c
@@ -426,7 +426,7 @@ puthdr(int fd, struct hdr *hdr)
 	    le32toh(eh.p[0].p_filesz));
 	eh.p[1].p_vaddr = eh.p[1].p_paddr =
 	    htole32(align(le32toh(eh.p[0].p_paddr) + le32toh(eh.p[0].p_memsz),
-	    4));
+	    4096));
 	eh.p[1].p_filesz = eh.p[1].p_memsz = htole32(hdr->data);
 	eh.sh[2].sh_addr = eh.p[0].p_vaddr;
 	eh.sh[2].sh_offset = eh.p[0].p_offset;


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201101090023.p090NaTe096165>