Archive for January, 2010

Change Congress

Lawrence Lessig is pushing for a constitutional amendment to change the campaign financing system. You can sign his petition over at

I think Lessig is right that campaign financing is broken. Elections for national office are very expensive. Politicians spend a lot of their time fund-raising. Jesse Unruh was probably reasonably accurate when he said, about lobbyists, “If you can’t eat their food, drink their booze, screw their women and still vote against them, you have no business being up here” (apologies for the sexism, I’m just quoting). And of course many politicians raise most of their money from small donations. But many do not, and of those who do not, they are far more likely to be elected in the first place if they hold views which are congenial to people who are willing to spend a lot of money on politicians. That increasingly means corporations rather than individuals. That leads to a increasing focus of government on the needs of the wealthy rather than on the needs of the general population. And that leads to an increasing distrust and dislike of government by the general population. And that doesn’t do anybody any good, regardless of one’s political position.

I also think that Lessig is right that the only way to fix campaign financing is a constitutional amendment. The Supreme Court was willing to overturn a hundred years of precedent in their recent decision permitting unlimited corporate speech. Clearly ordinary laws are insufficient. And while the amendment process is obviously very heavyweight, the constitution does after all provide a right of free speech, and campaign financing laws are indeed a limitation on speech; an amendment does not seem inappropriate.

Unfortunately, a constitutional amendment must be voted in by politicians. They would basically be voting away their present support and their future income (many politicians retire to become lobbyists themselves). Passing such an amendment would require overwhelming popular support, and I’m skeptical that that will happen.

Comments (1)

Go Linkage Names

All Go code lives in a package. Every Go source file starts with a package declaration which names the package that it lives in. A package name is a simple identifier; besides appearing in a package clause, package names are also used when referring to names imported from another package. That poses the problem of what to do when one program links together two different packages which use the same package name. We can’t expect the author of a large program to be aware of every package that the program uses. However, since Go compiles straight to object files, it’s natural to use the package name in the generated symbol names. How can we avoid multiple definition errors?

The gc compiler comes with its own Go specific linker. That linker now supports automatic symbol renaming at link time based on the name used to import the package. That name is presumed to be unique. This means that all imports of the same package must use the same name to import it; otherwise you might get multiple definitions of a global variable in the package. In the future there may be some need to adjust packages which are distributed without their source code, to ensure that they don’t accidentally alias locally compiled package names.

For the gccgo compiler I have so far avoided using a specific linker, or rather linker wrapper. For large programs gccgo now requires a new option, -fgo-prefix=PREFIX to be used when compiling a package. The PREFIX should be a string unique to that package; for example, in a typical installation, it could be the directory where the package is installed. This gives a unique name used in the compiled code. If the -fgo-prefix option is not used, everything will still work as long as there are not, in fact, two packages with the same name.

Comments (9)

Protected Symbols

Now for something really controversial: what’s wrong with protected symbols?

In an ELF shared library, an ordinary global symbol may be overridden if a symbol of the same name is defined in the executable or in a shared library which appears earlier in the runtime search path. This is called symbol interposition. It is often used with functions such as malloc. A shared library can define malloc and it can have code which calls malloc. If the executable linked with the shared library defines malloc itself, then the version in the executable will be used rather than the version in the shared library. This permits the executable to control the memory allocation done by the shared library, perhaps for debugging or logging purposes. In this regard, shared libraries act much as static archives do.

This has a few consequences. One of them is that within a shared library, all references to a global symbol must use the GOT and PLT, to make the overriding possible. That means that all function calls and variable accesses are slightly slower. Also, some compiler optimizations are forbidden: the compiler can not inline a call to a global symbol, since that symbol might be overridden at run time.

When building a shared library, you can provide a version script which indicates that some symbols are actually not global. That can eliminate the GOT and PLT accesses, but it does not permit the compiler optimizations, and you do have to write that version script and keep it up to date.

When compiling code that goes into a shared library, you can set the visibility of symbols. You can use hidden visibility, which means that the symbol is not visible outside the shared library. You can use internal visibility, which is a lot like hidden—I’ll skip the difference here. Or you can use protected visibility. Protected visibility means that the symbol is visible outside of the shared library, and can be accessed as usual. However, all references from within the shared library will use the definition in the shared library. In other words, the symbol acts more or less as usual, but it can not be overridden. This means that accesses to the symbol avoid the GOT and PLT, and it permits compiler optimizations.

So, what’s wrong with them? It turns out that protected symbols are slower at dynamic link time, which means that programs which use the shared library start up slower. This happens because of the C rule that two pointers to the same function must compare as equal. Since protected symbols are globally visible, you can get a pointer to a protected function in the main executable. You can also get a pointer to that same function in the shared library, of course. Those pointers have to be equal, or the C rule will break.

As noted, the access to the function in the shared library will not use the GOT or PLT. The access in the main executable obviously will use the PLT. How can we make those function pointers equal? We can’t. The executable will have a direct reference to the PLT. The shared library will have a direct reference to the function itself. In neither case will there be a relocation for the reference. So there is no way to make the results equal. (This can work for some targets, but not for ones with simple function references like the x86 targets.)

So, I must have lied. The lie was that there is a case where you need to use the GOT for a protected symbol: when compiling position independent code for a shared library, and taking the address of a protected function, you need to use the GOT. Unfortunately, gcc for the x86_64 target, surely the most widely used gcc target today, gets this wrong: This generally reveals itself as an error report when you go to create a shared library: relocation R_X86_64_PC32 against protected symbol `NAME' can not be used when making a shared object.

In any case, when the compiler gets it right, the dynamic linker has to fill in that GOT entry. In order to make the function pointers compare as equal, it has to fill in the entry with the address of the PLT in the executable (or the earlier shared library). But remember, this is a protected symbol, and protected symbols don’t support symbol interposition. So the dynamic linker must only use the PLT of the executable if the reference in the executable refers to the definition in the shared library. That means that when the dynamic linker sees a reloc against a protected symbol in a shared library, it has to do another walk through the executable and earlier shared libraries to see if any of them have a definition for the symbol, in which case the GOT entry must not be set to that earlier PLT entry but must instead be set to the address of the symbol in the shared library itself. This check has to be done for every symbol in the shared library.

Those extra symbol resolution passes means a slow down for every program which uses the shared library, and that is what is wrong with protected symbols.

So how do you get the compiler and linker speedups available by avoiding symbol interpositioning? Unfortunately, you have to give your symbols hidden visibility, which means that they can not be accessed from other modules. Assuming you do want them to be accessed, you need to define symbol aliases for the ones which should be publicly visible. That means that you need to use different names for the hidden symbols. This is awkward at best. Unfortunately I have nothing better to offer. ELF is designed to support symbol interpositioning, and there is no very good way to avoid that without causing other consequences.

Comments (2)


I’ll read anything which Iain Banks writes, but, frankly, his recent novel Transition was rather weak. I think he was a bit low on the idea bank for this one. This is one of the novels where he sets up surprises, but unfortunately they were not surprising. The ideas which were meant to be challenging and surprising just seemed wrong. The changes to the main character were poorly motivated. The explicit sex, which worked in his novel Complicity because it expanded the characterization, here seemed irrelevant and tossed in just to avoid a talking heads problem.

In a lesser writer, I would think that the ending was setting up a sequel. I sincerely hope that is not the plan here.

Separately, I’ve been reading NESFA’s nice series of collected Zelazny stories. Zelazny has always been one of my favorite SF authors, and it’s refreshing to be reminded of just how good he was. His novels were generally good, of course (avoid the second five Amber novels), but it was in his short stories that he really shone.


The Argent Age

The dramatic growth of income inequality in the U.S. over the last 30 to 40 years may mark the end of a long experiment in U.S. society, starting with Teddy Roosevelt and ending with Richard Nixon (things were already changing under Jimmy Carter). Teddy Roosevelt was the first of the progressive presidents, and was a major force in a shift in society in which government worked to limit the power of large corporations and guarantee basic rights like food and shelter to all citizens.

Those times are gone, and we have returned to the Gilded Age. Through a natural analogy with Greek mythology, I think we should call the present day the Argent Age. This is due to a broad shift in societal values: government is the problem, and business and the free market is the solution. The inevitable result is that an increasing number of people are poor and have little control over their own lives. In the Gilded Age their anger expressed itself in prairie populism which targeted financiers and politicians. In the Argent Age financiers aren’t doing so well at the moment, but the main anger is against politicians (again) and a somewhat imaginary liberal elite who are assumed to control the national discourse.

In both ages the wealthy by and large ignore the poor; when they consider them at all they tend to advocate a trickle-down theory. Rags-to-riches stories are prominent in both ages (Horatio Alger vs. American Idol), which serve as a form of bread and circuses. In both ages the wealthy exert enormous if somewhat hidden control over the political process.

The Gilded Age ended with Teddy Roosevelt and the Square Deal. He was a more or less accidental president, pushed onto the ticket as a vice-presidential candidate by a Republican boss who wanted him out of his position as governor of New York, and becoming president after McKinley’s assassination. Despite this inauspicious start, he immediately started working to curb the power of corporations, passing the Meat Inspection Act and the Pure Food and Drug Act, and making the serious use of the Sherman Antitrust Act.

The Argent Age will end too, but I can’t guess how. I hope we don’t have to wait for another Teddy Roosevelt; he was a true original.

Comments (26)

« Previous entries Next Page » Next Page »