From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <9605091055.ZM24522@aib.com> Date: Thu, 9 May 1996 10:55:15 -0400 From: Eric Youngdale Subject: Re: gdb In-Reply-To: >Well, that's obviously not true.. You said it yourself: the linker _does_ >need to know about it, so the assembler is wrong. If you assume the linker doesn't remove any code, then I don't see how the linker would need to know about local branches. >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. No, it isn't impossible - this is getting close to the sort of thing I get paid to do in my day job, and I know it can be done given enough care and persistance. I will agree that it is damn hard, however. One thing I could suggest however is that if the compiler is absolutely 100% strict about only putting executable code into the .text segment, then the problem becomes significantly easier. I would say that it is even doable. The question is how easy it would be to impose this restriction. On some architectures, it is not terribly complicated, but on others it imposes a significant hardship. If it is not possible to eliminate the use of non-executable code from the .text segment, then it would be possible to add special relocations to mark those regions of non-executable code in the text segment, so the linker still knows to do the right thing. >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). I agree, they have done some things right. The older 32 bit versions had some very strange features which must have driven the compiler and linker people crazy. Things like how their address space is divided into 4 1Gb quadrants - it is very expensive to call from one quadrant to another, especially when floating point is involved, so they added some hacks which basically allow certain functions to be performed without branching outside of the quadrant. With the 8000 series machine, they now have a 64 bit machine, and I am told that some of this stupidity goes away. The compiler people from HP that I have spoken to seem to get rather excited about no longer having to worry about this sort of crap :-). I have been told in all seriousness by people from HP that you should consider static linking programs for optimum performance (basically to avoid the overhead of branching to another quadrant - the executable is normally in quadrant 0, and shared libs are in quadrant 1 or 2 depending upon whether the debugger is in use or not). Anyways, let me explain some of the things they have done in their compilers and related tools. If you compile a program with the highest optimziation (+O4) under SoftBench, the compiler itself doesn't actually generate any code. It generates an internal representation of the parse tree, and it isn't easy for me to tell whether much in the way of optimization has been done at this point. When you go to link such a file, the linker itself collects all of the intermediate code that is supposed to go into the output image, and invokes the code generator (the same one the compiler invokes if lower levels of optimization are selected). The code generator is able to do all of the proper optimizations in order to optimize the *entire* image. I have been told by people from HP that there are limits to how large a program you can link in this manner - as you might imagine the VM usage can get rather impressively large. Anyways, to sum up, I think this is still a tractible problem for the linker to handle completely without any help from the assembler (other than some special relocation types to indicate non-executable code in the .text section). It is highly academic at this point anyways, since I have much more important things I need to be hacking right now anyways. I guess we are still looking for that elusive volunteer :-). -Eric -- "The woods are lovely, dark and deep. But I have promises to keep, And lines to code before I sleep, And lines to code before I sleep."