Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@cs.Helsinki.FI>
Subject: Re: gdb
Date: Thu, 9 May 1996 08:29:32 +0300 (EET DST)	[thread overview]
Message-ID: <2e9a845f78476131cc75f6b630eee0aa.axp-list@archive.invalid> (raw)
In-Reply-To: <m0uHMhd-0009UJC@her.platinum.com>

On Wed, 8 May 1996, Eric Youngdale wrote:
> 
> 	A few further thoughts.  I am not trying to put you off of the
> idea of optimizing in such a way that we don't leave nops behind, but
> I just want to impress upon you how difficult such a thing really is.

I _hope_ that it wouldn't be too difficult if we just did it the right 
way..

> 	Normally the assembler will resolve some things such as local
> branches without the need for emitting a relocation.  The idea is that
> the branch is pc-relative, so there is no point in wasting time and
> space by telling the linker about something which it doesn't need to
> handle anyways.

Well, that's obviously not true.. You said it yourself: the linker _does_ 
need to know about it, so the assembler is wrong.

> 	If we were to start removing instructions, it means that we
> have to repair all of these local branches.  One way of doing this
> would be to have the assembler emit everything as relocations instead
> of having it fill in fields that it thinks are fully resolved.  To do
> this, absolutely everything, including every local label in the file
> must be emitted into the object file so that it is possible for the
> linker to optimize the instructions away.
> 
> 	The other alternative to leaving ine information in the object
> file would be for the linker to do code reading to find all of the local
> branches, labelize them, optimize the code, and then use the labels
> to recompute all of the offsets for the local branches.  In fact this
> is probably preferable.

Umm, I really would prefer the assembler leaving enough information - 
otherwise the linker bugs will be so horrible to find that it's not worth 
it . In particular think about this kind of code:

	function:
		nop	/* align */
		br  $1,1f
		.quad 0xYYYYYYYYYYYYYYYY
		.quad 0xYYYYYYYYYYYYYYYY
	1:	ldq $2,0($1)
		ldq $3,8($1)
		...

Now look at that code: it's one way to pack in some static data in the 
code segment. Admittedly gcc doesn't do this, but it's actually useful 
for some very low-level assembly where you don't want to have the gp 
value at all..

Now, I don't want to be the linker who tries to find local labels in the 
above. Maybe the data values happen to have patterns that match a "bsr" 
instruction, and then the linker "fixes" it because there is some jsr we 
optimized somewhere.. Uggh..

So, making the linker fix things up is not only hard as h*ll, it's 
actually impossible.

So, now think of the problem without a fixed assembler.. What do we get?  We
get an assembler that isn't a "traditional" assembler any more: we just get a
smart pre-processor. Essentially, the assembler shouldn't emit runnable code,
it should emit runnable code _fragments_, and then the linker would be free
to pad those as it sees fit. You said the hpux setup did something that
sounded like this (and take a look at the currently fastest single-CPU
machine - it's not made by Digital. It's the HP PA-8000, so they have done
some things _right_, and the compiler is probably one of those things 
even though the memory subsystem seems to be quite good). 

We don't really have to be object-file compatible with OSF/1.. Doesn't 
the GNU linker already handle multiple different types of segments? We 
should be able to link normal ECOFF segments with the "fragment" setup 
without any fundamental problem (I'm not saying fragment handling is 
easy, but it shouldn't be fundamentally impossible).

With a fragmenting assembler, the assembler can do something like this:
 - assume that the jump is always local, do a "bsr", but also do a "end 
   fragment" at the bsr.
 - the linker reads in a stream of fragments, notices that "oops, we 
   can't do a bsr here", and expands the bsr to the proper address load 
   and jsr. If it _can_ do a "bsr", it obviously has to know where the 
   target is already, so it takes a look at the target, sees if there is 
   any "ldgp" sequence at the start, and fixes up the "bsr" to jump over 
   it.

You already showed some nervousness about the assembler creating the .lita
entries, so it seems there are some fundamental design mistakes in the
current setup, and maybe we _should_ be thinking about moving parts of the
assembler into the linker instead (others have done this for similar reasons
- you can do some other limited global optimizations with this same technique
where the assembler doesn't generate fixed code)

		Linus

  reply	other threads:[~1996-05-09  5:29 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-05-09  3:47 gdb Eric Youngdale
1996-05-09  5:29 ` Linus Torvalds [this message]
  -- strict thread matches above, loose matches on Subject: below --
1999-08-29  0:09 gdb Larry Snyder
1999-08-30 12:07 ` gdb Max Weninger
1999-08-30 15:20   ` gdb Michal Jaegermann
1999-08-30 17:12     ` gdb Max Weninger
1999-08-30 18:19       ` gdb Wes Bauske
1999-08-30 20:15         ` gdb Michal Jaegermann
1999-08-31  8:56         ` gdb Max Weninger
     [not found] <m0uM6E7-0001thC@atheist.tamu.edu>
1996-05-22 11:45 ` gdb Jim Nance
     [not found] <Pine.SUN.3.91.960510085342.3960A-100000@edge.edge.net>
1996-05-17 15:56 ` gdb Harald Koenig
     [not found] <Pine.LNX.3.91.960509080842.11981C-100000@linux.cs.Helsinki.FI>
1996-05-09 15:43 ` gdb Richard Henderson
     [not found] <richard@atheist.tamu.edu>
1996-05-09 14:55 ` gdb Eric Youngdale
     [not found] <Pine.LNX.3.91.960508210447.27170G-100000@linux.cs.Helsinki.FI>
1996-05-09  8:16 ` gdb Harald Koenig
1996-05-09  4:34 gdb David Mosberger-Tang
1996-05-08 20:15 gdb Richard Henderson
1996-05-09  8:23 ` gdb Harald Koenig
1996-05-09 16:04   ` gdb Richard Henderson
1996-05-08 19:07 gdb Richard Gorton
1996-05-08 18:51 gdb Craig Burley
1996-05-08 17:53 gdb David Mosberger
1996-05-08 18:16 ` gdb Linus Torvalds
     [not found] <torvalds@cs.Helsinki.FI>
1996-05-08 17:19 ` gdb Eric Youngdale
1996-05-08 18:24 ` gdb Eric Youngdale
1996-05-07 14:23 gdb David Mosberger-Tang
1996-05-07 15:48 ` gdb Richard Henderson
1996-05-07  6:32 gdb Harald Koenig
1996-05-08 17:06 ` gdb Linus Torvalds
read-only archive

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