Archive

Posts Tagged ‘gcc’

Compiler writing in the next decade

December 22nd, 2009 Derek-Jones 1 comment

What will be the big issues in compiler writing in the next decade? Compilers sit between languages and hardware, with the hardware side usually providing the economic incentive.

Before we set off to follow the money, what about the side that developers prefer to talk about. The last decade has not seen any convergence to a very small number of commonly used languages, if anything there seems to have been a divergence with more languages in widespread use. I will not attempt to predict whether there will be a new (in the sense of previously limited to a few research projects) concept that is widely integrated and used in many languages (i.e., the integrating of object oriented features into languages in the 90s).

Where is hardware going?

  • Moore’s law stops being followed. Moore’s law is an economic one that has a number of technical consequences (e.g., less power consumed and until recently increasing clock rates). Will the x86 architecture evolution dramatically slow down once processor manufacturers are no longer able to cram more transistors onto the same amount of chip real estate? Perhaps processor designers will start looking to compiler writers to suggest functionality that could be made use of by compilers to generate more optimal code. To date my experience of processor designers is that they look to Moore’s law to get a ‘free’ performance boost.

    There are a number of things a compiler code tell the processor, such as when a read or write to a cache line is the last one that will occur for a long time (enabling that line to be moved to the top of the reuse list).

  • Not plugged into the mains. When I made a living writing optimizers the only two optimizations choices were code size and performance. There are a surprising number of functional areas in which a compiler, given processor support, can potentially generate code that consumes less power. More on this issue in a later post.
  • More than one processor. Figuring out how to distribute a program across multiple, loosely coupled, processors remains a difficult research topic. If anybody ever comes up with a solution to this problem it might make more commercial sense for them to keep it secret, selling a compiling service rather than selling compilers.
  • Application Specific Instruction-set Processors. Most processors in embedded systems only ever run a single program. The idea of each program being executed on a processor optimized to its requirements sounds seductive. At the moment the economics are such that it is cheaper to take an existing, very low cost, processor and shoe-horn the application onto it. If the economics change the compiler used for each processor is likely to be automatically generated.

Enough of the hardware, this site is supposed to be about code:

  • New implementation techniques. These include GLR parsing and genetic algorithms to improve the generated code quality. The general availability of development machines containing more than 4G of memory will make it worthwhile for compiler writers to implement more whole program optimizations (which are currently being hemmed in by storage limits)
  • gcc will continue its rise to world domination. The main force at work here is not the quality of gcc but the disappearance of the competition. Compiler writing is not a big bucks business and compiler companies are regularly bought up by much larger hardware outfits looking to gain some edge. A few years go by, plans change, the compiler group are not making enough profit to warrant the time being spent on them by upper management and they are closed down. One less compiler vendor and a bunch of developers are forced to migrate to another compiler, which may or may not be gcc.
  • Figuring out what the developer meant to write based on what they actually wrote, and some mental model of software developers, is my own research interest. This is somewhat leading edge stuff, in other words nothing major has been achieved so far. Knowledge of developer intent looks like it will open the door to whole classes of new optimization techniques.

Compiler writing: The career path to World domination

November 7th, 2009 Derek-Jones 3 comments

Compiler writing is not usually thought of as a career path that leads to becoming Ruler of the World. Perhaps this is because compiler writing is a relatively new profession and us compiler writers are still toiling in obscurity awaiting the new dawn.

What might be a workable plan for a compiler writer to become Ruler of the World? One possibility is to write a compiler for the language in which most of the World’s critical software is written (i.e., C) and for that compiler to become the one that the vendors of this critical software all use (i.e., gcc). This compiler needs to do more that just compile the source code it is feed, it also needs to generate code that creates a backdoor in important programs (e.g., the login program).

But, you say, this cannot happen with gcc because its source is available for everybody to read (and spot any backdoor generator). In his 1984 Turing acceptance lecture Ken Thompson showed how a compiler could contain a backdoor that was not visible in its source. The idea is for the compiler writer to modify a compiler to detect when it is being used to compile itself and to insert the backdoor generating code into its own executable. This modified compiler is then used to compile itself and the resulting executable made the default compiler; the backdoor modifications are then removed from the compiler source, they are no longer needed because the previously compiled compiler will spot when it is being used to compile its own source and generate the code necessary to propagate the backdoor code into the executable it creates.

How would the world counter the appearance of such a modified gcc? Obviously critical programs would need to be recompiled by a version of gcc that did not contain the backdoor. Today there are several companies and many amateur groups that distribute their own Linux distributions which they build from source. It should be relatively easy to obtain a usable executable of gcc from 10 years ago; remember what is needed is a version capable of compiling the latest gcc sources.

The ideal time to create a backdoor’ed version of gcc is while its development was under the control of one person, so early in the development history that all versions available anywhere are very likely to be derived from it. How can we prove that the original author of gcc did not do just this?

It could be argued that the very substantial changes to the gcc sources (most of the source has probably been rewritten several times) mean that the coding patterns searched for by the executable to detect that it is compiling itself have long gone and at some point the backdoor failed to propagate itself to the next executable.

Compilers other than gcc might also include backdoors that propagate themselves. However, the method of propagation is likely to be different. Compiling the gcc sources with a non-gcc compiler creates an executable that should exhibit the same behavior as a gcc-compiled executable. Differences in the behavior of these independently built executables is a cause for concern (one difference might be caused by differences in the conversion of floating-point literals, a recent PhD thesis provides more detail).

The problem with compiling the gcc sources is that they make use of language extensions that few, if any, other compilers support. I know IBM added modified one of their C compilers to support those gcc extensions needed to compile the Linux kernel, but I don’t know if this compiler is capable of compiling the gcc sources. The LLVM project intended to support many gcc extensions but I don’t know if they aim to be able to compile the gcc sources.

Another option is to compare the assembler generated when gcc compiles itself against the corresponding source code. A very expensive task for source code measured in hundreds of thousands of lines. Adding the necessary language extension support to another compiler would probably be cheaper and also create a tool that could be used to check future releases of gcc.

Searching for the source line implementing 3n+1

June 30th, 2009 Derek-Jones No comments

I have been doing some research on the variety of ways that different developers write code to implement the same specification and have been lucky enough to obtain the source code of approximately 6,000 implementations of a problem based on the 3n+1 algorithm. At some point this algorithm requires multiplying a value by three and adding one, e.g., n=3*n+1;.

While I expected some variation in the coding of many parts of the algorithm I did not expect to see much variation in the 3n+1 part, perhaps somebody might write n=n*3+1;. I was in for a surprise, the following are some of the different implementations I have seen so far:

n = n + n + n + 1 ;
n += n + n + 1;
n = (n << 1) + n + 1;
n += (n << 1) + 1;
n *= 3; n++;
t = (n << 1) ; n = t + n + 1;
n = (n << 2) - n + 1;

I was already manually annotating the source and it was easy for me to locate the line implementing 3n+1 to annotate it. But what if I wanted to automate the search for the line of code containing this calculation, what tool could I use? Would I have to write down every possible ways in which 3n+1 could be implemented, with/without parenthesis and all possible orderings of operands? I am not aware of any automatic tool that could be told to locate expressions that calculated 3n+1. What is needed is abstract interpretation over short sequences of statements.

I mentioned this search problem over drinks after a talk I gave at the Oxford branch of the ACCU last week and somebody (Huw ???) suggested that perhaps the code generated by gcc would be the same no matter how 3n+1 was implemented. I could see lots of reasons why this would not be the case, but the idea was interesting and worth investigation.

At the default optimization level the generated x86 code is different for different implemenetations, but optimizing at the “-O 3″ level results in all but one of the above expressions generating the same evaluation code:

   leal 1(%rax,%rax,2), %eax

The exception is (n << 2) - n + 1 which results in shift/subtract/add. Perhaps I should report this as a bug in gcc :-)

I was surprised that gcc exhibited this characteristic and I plan to carry out more tests to trace out the envelope of this apparent “same generated code for equivalent expressions” behavior of gcc.

Predictions for 2009

December 31st, 2008 Derek-Jones 1 comment

If the shape of code does change over time, it changes very slowly. Styles become more or less popular, but again the time-scale is generally longer than a year. Anyway, here are my predictions for goings on the in the community that shapes code.

1) Functional programming will continue to entrance the young whose idealism will continue to be dashed when they have to deal with the real world. Ok, I started with something obvious that will still be true in 20 years and I promise not to to to keep repeating myself on this one every year.

2) The LLVM project will die. I am surprised that it has lasted this long, but it is probably costing Apple so little that it is not on management’s radar. Who needs another C compiler; perhaps 10 years ago they could have given the moribund gcc project a run for its money, but an infusion of keen people and a complete reworking of its internals has kept gcc as the leading contender to be the only C compiler developers use in 10 years time.

3) Static analysis will go mainstream. The driving force will not be developers loosing their aversion to being told of their mistakes, but because the world’s economic predicament will force them to deliver better performance in less time, ie they will be forced to use tools to help them find coding faults. The fact that various groups are starting to add hooks to the mainstream compilers (e.g., Microsoft’s Phoenix, gcc’s Dehydra), ensuring compatibility with an existing code base and making it easier for developers use, also helps. The gcc people may yet shoot themselves in the foot. Of course people will continue to develop new stand-alone tools and extract money from government to do something that sounds useful.

4) Natural language programming will finally gain a foothold. One of the big unnoticed announcements of the year was the Attempto project releasing the source code of their controlled English system.

5) The rate of gcc’s progress to world domination will accelerate. There are still quite a few market niches where gcc is a minority player (eg, embedded systems) and various compilers need to disappear for it to gain market share. Compiler writing has never been a very profitable business and compiler companies usually go bust or are taken over by hardware vendors looking for customer lock-in. The current economic situation means that compiler companies are both more likely to go bust and to not be brought, ie, their compilers will (commercially) disappear.

6) The number of people involved in writing software will continue to decline in the West and increase in the East. These days there is not a lot of difference in cost between east/west, it is the quality of developers (or rather there are more of a reasonable standard available). The declining standards in science/engineering education is the driving factor, the economic situation is just creating extra exposure.

FireStats icon Powered by FireStatscialis from canada

cialis 30 mg

generic cialis india discount

buy levitra online

buy cialis

cialis discounts

cialis low price

growth hair propecia

cialis iop

buy propecia online from usa pharmacy

buy cialis once daily

cialis brand

buy viagra without prescription

buy cialis online without prescription

discount levitra purchase

brand name cialis overnight

buy canada levitra

cialis samples in canada

can i order viagra from the chemist

levitra or viagra

canadian pharmacy cialis pfizer

ganeric cialis

cheap propecia uk

buy prescription propecia

buy levitra uk

cialis professional

discount propecia rx

cialis dosage mg

canadian healthcare viagra

5mg propecia

how much cialis

cheap propecia order online

5 mg original brand cialis

buy propecia online pharmacy

levitra tablets

best price for propecia online

cialis on line pricing in canada

canadian pharmacy discount code viagra

healthcare canadian pharmacy

hydrochlorothiazide cialis

indian cialis

cialis no prescription

cheap fast levitra

can i get viagra in mexico

drug hair loss propecia

levitra mg

buy prescription propecia

levitra in mexico

online propecia uk

buying cialis online

cialis and women

cialis dose

overnight delivery cialis

cialis for less 20 mg

generic propecia canada

online propecia prescription

cialis cheap

generic propecia mastercard

buy cialis professional

cheapest online propecia

canadian pharmacy viagra legal

best online levitra

canada propecia prescription

buy generic propecia online

cialis by mail

buy online propecia

discount generic propecia

buy cialis in usa

cheap cialis from india

cheap viagra canada or india

buy cialis without prescription

bruising on cialis

buy cialis 5 mg

buy cheap propecia

cialis buy

buy propecia online cheap pharmacy

lowest price on non generic levitra

cialis

cialis fast

cheap propecia 5mg

buy generic levitra online

cheap online propecia

generic viagra in canada

levitra sex pill

buy cheapest propecia

generic propecia uk

buy propecia where

best price on propecia

cialis daily in canada

50 mg cialis dose

best propecia prices

cialis daily in canada

ordering viagra

cheap propecia uk

buy cialis next day delivery

levitra online overnight delivery

canadian viagra generic

buy levitra now

buying cialis

5 mg cialis

buy cialis online canada

generic propecia sale

brand cialis for sale

generic viagra 100 mg

canada viagra generic

cialis iop

canada levitra

canadian online pharmacy cialis

cialis kanada

best price for propecia

cialis daily cost

cheap viagra

cialis pharmacy

buy branded viagra online

generic levitra purchase

cheapest viagra online

cialis canadian pharmacy

buy 5 mg cialis

online cheap viagra

buy viagra

indian cialis canada

generic propecia effective

buy pfizer viagra in canada

buy cialis canada

cialis canada online pharmacy

drug generic propecia

next day viagra

levitra discount

levitra online sales

cialis dosage

canada generic propecia

buy 5 mg cialis

cheap cialis

cialis daily availability

buy xenical propecia

buy cialis without a prescription

order usa viagra online

canadian pharmacy cialis

cialis daily canada

buying cialis soft tabs 100 mg

buy dosages levitra

ordering cialis gel

generic cialis soft tabs

buying viagra with no prescription

buy levitra online no prescription

lowest price propecia

buy levitra online from canada

cialis delivered overnight

buy cialis without a prescription

cialis brand only

50 mg cialis dose

buy canada in propecia

buy now viagra

best price propecia

levitra in india

cialis testimonial

cheap viagra on line

cialis canada illegal buy

buying viagra

cialis tablets foreign

buy cialis online canada

buy real cialis

canadian pharmacy cialis pfizer

dose cialis

cialis by women

5mg propecia

cialis price 100 mg

cialis on sale

cheap propecia no prescription

buying cialis without a prescription

buy propecia without a prescription

cialis woman

canadian women viagra

one day delivery cialis

cheap price propecia

cialis brand only

buy cialis once daily

order propecia online

best levitra price

buy propecia online

buy vardenafil levitra

best deal for propecia

cheap levitra prescription

buying levitra online

cialis daily dosing cost

cialis soft tabs

buy cialis in canada

canadian levitra

buy viagra in canada

generic levitra canada

buy propecia international pharmacy

buy branded viagra

buying cialis soft tabs 100 mg

buying propecia

buy cheap generic levitra

best way to use cialis

buy cheap levitra online

cialis for women

buy cialis online

how much does cialis cost

buy propecia no prescription

buying viagra with no prescription

brand viagra without prescription buy

generic levitra cialis

cialis fast delivery

cheap cialis soft

mexico propecia

brand viagra professional

best levitra prices

cheapest prices on propecia

cialis dosage mg

levitra ed

original brand cialis

cialis fast delivery usa

canadian viagra india

brand name cialis

canadian propecia cheap

buying real viagra without prescription

buy daily cialis

generic cialis professional

online propecia sales

generic levitra pill

cheap online propecia

canada viagra pharmacies scam

buy generic propecia online

cheap cialis

buy cialis next day delivery

buy levitra uk

cialis philippines

cheap canadian viagra

generic propecia for sale

buy real viagra online without prescription

buying viagra

buy propecia in the uk

cialis in mexico

buy propecia uk

cialis from india

getting cialis from canada

best doses for propecia

canadian healthcare

online propecia prescriptions

mail order propecia

online viagra

get viagra

buy canada in propecia

herbal propecia

buy cheap generic propecia

cialis headaches

canada viagra pharmacies scam

cialis soft tablets