Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* strip 2.6 breaks images
@ 1996-05-14 17:10 Harald Koenig
  1996-05-14 21:59 ` Richard Henderson
  0 siblings, 1 reply; 5+ messages in thread
From: Harald Koenig @ 1996-05-14 17:10 UTC (permalink / raw)


strip 2.6 (from Red Hat AXP 3.0.3) breaks [some] binaries.
quickstrip doesn't show this problem and produces smaller binaries.
example:

	# echo "main() { while(1); }" > idle.c
	# cc idle.c
	# ll a.out
	-rwxrwxr-x   1 root     root        72128 May 14 19:13 a.out
	# ./a.out
	^C
	# strip a.out
	-rwxrwxr-x   1 root     root        40960 May 14 19:13 a.out
	# ./a.out
	Segmentation fault (core dumped)
        # cc idle.c
	# quickstrip a.out
	# a.out truncated at 32768
        # ll a.out
	-rwxrwxr-x   1 root     root        32768 May 14 19:13 a.out
        # ./a.out
        ^C
	# strip a.out
	-rwxrwxr-x   1 root     root        40960 May 14 19:13 a.out
	# ./a.out
	Segmentation fault (core dumped)

Harald

-- 
All SCSI disks will from now on                     ___       _____
be required to send an email notice                0--,|    /OOOOOOO\
24 hours prior to complete hardware failure!      <_/  /  /OOOOOOOOOOO\
                                                    \  \/OOOOOOOOOOOOOOO\
                                                      \ OOOOOOOOOOOOOOOOO|//
Harald Koenig,                                         \/\/\/\/\/\/\/\/\/
Inst.f.Theoret.Astrophysik                              //  /     \\  \
koenig@tat.physik.uni-tuebingen.de                     ^^^^^       ^^^^^

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: strip 2.6 breaks images
  1996-05-14 17:10 strip 2.6 breaks images Harald Koenig
@ 1996-05-14 21:59 ` Richard Henderson
  1996-05-14 23:21   ` Harald Koenig
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Henderson @ 1996-05-14 21:59 UTC (permalink / raw)


> strip 2.6 (from Red Hat AXP 3.0.3) breaks [some] binaries.

I have never seen this with any version of the binutils, which 
makes me wonder if there is some libbfd compatibility problem
as with the insmod problem that was reported recently.

Have you tried rebuilding it?

r~

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: strip 2.6 breaks images
  1996-05-14 21:59 ` Richard Henderson
@ 1996-05-14 23:21   ` Harald Koenig
  1996-05-15 16:13     ` Richard Henderson
  0 siblings, 1 reply; 5+ messages in thread
From: Harald Koenig @ 1996-05-14 23:21 UTC (permalink / raw)


> > strip 2.6 (from Red Hat AXP 3.0.3) breaks [some] binaries.
> 
> I have never seen this with any version of the binutils, which 
> makes me wonder if there is some libbfd compatibility problem
> as with the insmod problem that was reported recently.

can't you reproduce this with my very small idle program ?

> Have you tried rebuilding it?

I just rebuilt strip from binutils-2.6-4.src.rpm (only rpm -i, 
then rpm -bp, configure and make...), same result:
the small idle program dumps core when stripped  :-(

Harald

-- 
All SCSI disks will from now on                     ___       _____
be required to send an email notice                0--,|    /OOOOOOO\
24 hours prior to complete hardware failure!      <_/  /  /OOOOOOOOOOO\
                                                    \  \/OOOOOOOOOOOOOOO\
                                                      \ OOOOOOOOOOOOOOOOO|//
Harald Koenig,                                         \/\/\/\/\/\/\/\/\/
Inst.f.Theoret.Astrophysik                              //  /     \\  \
koenig@tat.physik.uni-tuebingen.de                     ^^^^^       ^^^^^

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: strip 2.6 breaks images
  1996-05-14 23:21   ` Harald Koenig
@ 1996-05-15 16:13     ` Richard Henderson
  1996-05-17 23:31       ` Harald Koenig
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Henderson @ 1996-05-15 16:13 UTC (permalink / raw)


> > I have never seen this with any version of the binutils, which 
> > makes me wonder if there is some libbfd compatibility problem
> > as with the insmod problem that was reported recently.
> 
> can't you reproduce this with my very small idle program ?

Ack.  You were right.

There was a problem, but in the kernel rather than the binutils.
The kernel was ignoring the file offset information so kindly
provided to it in the ECOFF section headers.

Following is a patch that fixes the problem.

WARNING: I found while testing this patch that my /sbin/getty from
RedHat 2.1 was actually broken, that is, it contained inconsistant
offset information.  The one from 3.0.3 is Righteous.

r~

Index: binfmt_aout.c
===================================================================
RCS file: /home/richard/Repository/linux/linux/fs/binfmt_aout.c,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 binfmt_aout.c
--- binfmt_aout.c	1996/04/28 06:19:06	1.1.1.2
+++ binfmt_aout.c	1996/05/15 15:43:12
@@ -261,8 +261,9 @@
 	int fd;
 	unsigned long error;
 	unsigned long p = bprm->p;
-	unsigned long fd_offset;
 	unsigned long rlim;
+	unsigned long text_offset, text_addr;
+	unsigned long data_offset, data_addr, bss_addr;
 
 	ex = *((struct exec *) bprm->buf);		/* exec-header */
 	if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != OMAGIC && 
@@ -273,20 +274,62 @@
 	}
 
 	current->personality = PER_LINUX;
-	fd_offset = N_TXTOFF(ex);
+
+#ifdef __alpha__
+	text_addr = N_TXTADDR(ex);
+	data_addr = N_DATADDR(ex);
+	bss_addr = N_BSSADDR(ex);
+
+	/* Read the ECOFF section headers to find the actual file 
+	   positions of the text and data segments.  */
+	{
+		struct scnhdr scns[ex.fh.f_nscns];
+		unsigned long i;
+
+		read_exec(bprm->inode, sizeof ex, (char*)scns, sizeof scns, 1);
+
+		text_offset = data_offset = ~0UL;
+
+#define SEC(a,b,c,d,e) a|(b<<8)|(c<<16)|(d<<24)|((unsigned long)e<<32)
+		for (i = 0; i < ex.fh.f_nscns; ++i)
+			switch (*(unsigned long *)scns[i].s_name)
+			{
+			    case SEC('.','t','e','x','t'):
+				text_offset = (scns[i].s_scnptr -
+					       (scns[i].s_vaddr & 0xfff));
+				break;
+			    case SEC('.','d','a','t','a'):
+			        data_offset = (scns[i].s_scnptr -
+					       (scns[i].s_vaddr & 0xfff));
+				break;
+			}
+#undef SEC
+
+		i = bprm->inode->i_size;
+		if (text_offset >= i || text_offset+ex.a_text > i ||
+		    data_offset >= i || data_offset+ex.a_data > i)
+			return -ENOEXEC;
+	}
+#else
+	text_addr = N_TXTADDR(ex);
+	data_addr = N_DATADDR(ex);
+	bss_addr = N_BSSADDR(ex);
+	text_offset = N_TXTOFF(ex);
+	data_offset = text_offset + ex.a_text;
 
 #ifdef __i386__
-	if (N_MAGIC(ex) == ZMAGIC && fd_offset != BLOCK_SIZE) {
+	if (N_MAGIC(ex) == ZMAGIC && text_offset != BLOCK_SIZE) {
 		printk(KERN_NOTICE "N_TXTOFF != BLOCK_SIZE. See a.out.h.\n");
 		return -ENOEXEC;
 	}
 
 	if (N_MAGIC(ex) == ZMAGIC && ex.a_text &&
-	    (fd_offset < bprm->inode->i_sb->s_blocksize)) {
+	    (text_offset < bprm->inode->i_sb->s_blocksize)) {
 		printk(KERN_NOTICE "N_TXTOFF < BLOCK_SIZE. Please convert binary.\n");
 		return -ENOEXEC;
 	}
-#endif
+#endif /* i386 */
+#endif /* alpha */
 
 	/* Check initial limits. This avoids letting people circumvent
 	 * size limits imposed on them by creating programs with large
@@ -302,11 +345,11 @@
 	flush_old_exec(bprm);
 
 	current->mm->end_code = ex.a_text +
-		(current->mm->start_code = N_TXTADDR(ex));
+		(current->mm->start_code = text_addr);
 	current->mm->end_data = ex.a_data +
-		(current->mm->start_data = N_DATADDR(ex));
+		(current->mm->start_data = data_addr);
 	current->mm->brk = ex.a_bss +
-		(current->mm->start_brk = N_BSSADDR(ex));
+		(current->mm->start_brk = bss_addr);
 
 	current->mm->rss = 0;
 	current->mm->mmap = NULL;
@@ -314,13 +357,16 @@
 	current->sgid = current->egid = current->fsgid = bprm->e_gid;
  	current->flags &= ~PF_FORKNOEXEC;
 	if (N_MAGIC(ex) == OMAGIC) {
+load_unmapped:
 #ifdef __alpha__
-		do_mmap(NULL, N_TXTADDR(ex) & PAGE_MASK,
-			ex.a_text+ex.a_data + PAGE_SIZE - 1,
+		do_mmap(NULL, text_addr & PAGE_MASK,
+			data_addr+ex.a_data - (text_addr & PAGE_MASK),
 			PROT_READ|PROT_WRITE|PROT_EXEC,
 			MAP_FIXED|MAP_PRIVATE, 0);
-		read_exec(bprm->inode, fd_offset, (char *) N_TXTADDR(ex),
-			  ex.a_text+ex.a_data, 0);
+		read_exec(bprm->inode, text_offset, (char *)text_addr,
+			  ex.a_text, 0);
+		read_exec(bprm->inode, data_offset, (char *)data_addr,
+			  ex.a_data, 0);
 #else
 		do_mmap(NULL, 0, ex.a_text+ex.a_data,
 			PROT_READ|PROT_WRITE|PROT_EXEC,
@@ -338,36 +384,31 @@
 		file = current->files->fd[fd];
 		if (!file->f_op || !file->f_op->mmap) {
 			sys_close(fd);
-			do_mmap(NULL, 0, ex.a_text+ex.a_data,
-				PROT_READ|PROT_WRITE|PROT_EXEC,
-				MAP_FIXED|MAP_PRIVATE, 0);
-			read_exec(bprm->inode, fd_offset,
-				  (char *) N_TXTADDR(ex), ex.a_text+ex.a_data, 0);
-			goto beyond_if;
+			goto load_unmapped;
 		}
 
-		error = do_mmap(file, N_TXTADDR(ex), ex.a_text,
+		error = do_mmap(file, text_addr, ex.a_text,
 			PROT_READ | PROT_EXEC,
 			MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
-			fd_offset);
+			text_offset);
 
-		if (error != N_TXTADDR(ex)) {
+		if (error != text_addr) {
 			sys_close(fd);
 			send_sig(SIGKILL, current, 0);
 			return error;
 		}
 		
- 		error = do_mmap(file, N_DATADDR(ex), ex.a_data,
+ 		error = do_mmap(file, data_addr, ex.a_data,
 				PROT_READ | PROT_WRITE | PROT_EXEC,
 				MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
-				fd_offset + ex.a_text);
+				data_offset);
 		sys_close(fd);
-		if (error != N_DATADDR(ex)) {
+		if (error != data_addr) {
 			send_sig(SIGKILL, current, 0);
 			return error;
 		}
 	}
-beyond_if:
+
 	if (current->exec_domain && current->exec_domain->use_count)
 		(*current->exec_domain->use_count)--;
 	if (current->binfmt && current->binfmt->use_count)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: strip 2.6 breaks images
  1996-05-15 16:13     ` Richard Henderson
@ 1996-05-17 23:31       ` Harald Koenig
  0 siblings, 0 replies; 5+ messages in thread
From: Harald Koenig @ 1996-05-17 23:31 UTC (permalink / raw)


> There was a problem, but in the kernel rather than the binutils.
> The kernel was ignoring the file offset information so kindly
> provided to it in the ECOFF section headers.
> 
> Following is a patch that fixes the problem.
> 
> WARNING: I found while testing this patch that my /sbin/getty from
> RedHat 2.1 was actually broken, that is, it contained inconsistant
> offset information.  The one from 3.0.3 is Righteous.

using your linux/fs/binfmt_aout.c patch breaks at least some other images.
for some binaries I just get 

	cannot execute binary file

(e.g. emacs and static binaries from DEC Unix), others give a segmentation fault 
immidieately when executed (strace shows *no* system call at all; e.g. some
dynamic DU images).

Harald

-- 
All SCSI disks will from now on                     ___       _____
be required to send an email notice                0--,|    /OOOOOOO\
24 hours prior to complete hardware failure!      <_/  /  /OOOOOOOOOOO\
                                                    \  \/OOOOOOOOOOOOOOO\
                                                      \ OOOOOOOOOOOOOOOOO|//
Harald Koenig,                                         \/\/\/\/\/\/\/\/\/
Inst.f.Theoret.Astrophysik                              //  /     \\  \
koenig@tat.physik.uni-tuebingen.de                     ^^^^^       ^^^^^

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1996-05-17 23:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-05-14 17:10 strip 2.6 breaks images Harald Koenig
1996-05-14 21:59 ` Richard Henderson
1996-05-14 23:21   ` Harald Koenig
1996-05-15 16:13     ` Richard Henderson
1996-05-17 23:31       ` Harald Koenig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox