bin/153801: [patch] btxld produces incorrect ELF binaries

Gleb Kurtsou gleb.kurtsou at gmail.com
Sun Jan 9 00:30:05 UTC 2011


>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:


More information about the freebsd-bugs mailing list