GCC for kernel hackers  

Posted by Daniela Mehler

GCC for kernel hackers

A new Tim Jones tutorial overviews GNU Compiler Collection (GCC) extensions to ANSI C that may be of special interest to Linux kernel and driver developers. Meanwhile, the GCC development team is readying a new 4.4.0 release with stricter preprocessor checks, among other new features.

The GCC project appears to be on the cusp of releasing 4.4.0, with only regression fixes and documentation updates being accepted, according to Martin Michlmayr, former Debian project leader. Michlmayr reports that he compiled Debian with a 4.4 pre-release, finding 220 errors, most easily fixed. "The majority of GCC 4.4 build errors are missing #include statements. There are also about 20 build errors because of improved preprocessor checks," Michlmayr wrote.

Meanwhile, IBM DeveloperWorks has published another in its series of tutorials on GCC 4. Entitled, "GCC hacks in the Linux kernel," it was written by Tim Jones, who also recently surveyed new features in GCC 4.0 in and earlier article.

The Linux kernel is highly dependent on GCC, especially in enabling Linux on new architectures, writes Jones, a consulting engineer at Emulex. The kernel uses GCC extensions to implement a variety of shortcuts and simplifications for developers, as well as provide the compiler with "hints for optimization," writes Jones. In the article, Jones explores nine functions, including six aimed at adding functionality, and three aimed at binary optimization:Functional additions:
Type discovery -- This generic programming extension permits the identification of a type by referencing a variable.

Range -- Jones shows how range extensions can be used for initializations, as well as simplifying case statements within switch/case blocks.

Zero-length arrays -- This example shows how to use zero-length arrays to permit a structure element to reference memory that follows and is contiguous with the structure instance. This is particularly useful when a variable number of array members is required, writes Jones.

Determining call address -- GCC's "__builtin_return_address" function is typically used for debugging.

Constant detection -- Is a value a constant at compile-time? Only the constant detection extension knows for sure. The Linux kernel makes frequent use of this extension, writes Jones.

Function attributes -- Here, Jones surveys those attributes that are associated with functionality, including always_incline, deprecated, __used__, __const__, and warn_unused_result.
Optimizations:
Branch prediction hints -- This frequently used extension helps indicate the likelihood of the results of conditional code.

Prefetching -- Used to cache data in memory close to the processor, the prefetching extension is frequently employed by the Linux kernel by means of macros and wrapper functions.

Variable attributes -- This class of attributes is used for variables and type definitions. Jones explores the "aligned" attribute, which is used for object alignment in memory.Availability

The IBM DeveloperWorks tutorial by Tim Jones, "GCC hacks in the Linux kernel," should be available here.




New kernel boosts embedded
Guns N’ Roses to release new album next month
(Reuters)

This entry was posted on 4:38 AM .