Definition
A signed source-group difference is the change, new build minus old build, in the number of bytes that one group of source files contributes to a program image: positive if the group grew, negative if it shrank. Each byte is assigned to a group by the source file that the linker §12.4 map names for it; the linker map is the linker’s listing of every function and variable with its size and origin. Attribution is this assignment of bytes to groups. It is accounting, not a statement of cause.
Where it fits
Main entry: Causal inference (§11.11).
The groups, for example one per directory or per library, must form a partition: every byte of the image belongs to exactly one group. Bytes that no source file owns need a group of their own. Two examples are alignment §4.22 padding (filler bytes that move the next item to an address that is a multiple of 4 or 8) and code that the linker itself generates. Then the total change is the sum of the signed group changes. With changes of +100, and +20 bytes, the image grows by bytes. Leaving out the negative bar gives bytes, which is not the change of the image.
A bar shows where bytes ended up, not which change put them there. A change in one group can move bytes in another group in four common ways.
Library code pulled in. A linker adds code from a library only when the program refers to it, and many embedded builds also tell the linker to discard every function that nothing refers to. A new call in group A therefore makes the library’s bar grow.
Inlining. The compiler may copy a function’s body into each caller. With link-time optimization §12.10 (LTO), which optimizes all source files together when they are linked, a function from group B can be inlined into code of group A, so machine code that comes from B’s source appears in A’s bar.
Dead-code elimination §12.11, the removal of code that never runs or whose result is never used, can delete a function in group B once group A stops calling it.
Shifts and sharing. Inserted bytes move everything after them and change the padding. A linker can also keep one copy of a constant string that several files define identically, so its bytes appear in one group or in none.
Changes can also interact. Two features, X in group A and Y in group B, both call a 30-byte helper function §2.19 in a library group L, and nothing else calls the helper. With neither feature, the helper is left out of the image. Enabling X alone adds the 70 bytes of X and the 30 bytes of the helper, +100 bytes in all, and the bar of L shows +30. Enabling Y alone adds its 50 bytes and the helper, +80 bytes. Enabling both adds bytes, not , because the helper is included once. So X costs 100 bytes in a build without Y and bytes in a build with Y. The 30 bytes in the bar of L are caused by X or Y, although L itself did not change.
A causal claim, a claim about what a change does, needs an intervention: two builds that differ only in that change, with the same compiler, the same options and the same other source files, and a comparison of their totals. Changes that may interact need every combination built, as above. The causal inference entry explains the difference between an observed difference and the effect of an intervention. All numbers in this entry’s examples are invented.
Questions answered
Does this prove that one module caused its entire bar?
No. A bar in a chart of signed source-group differences shows how many bytes changed in the part of the program image that the linker map attributes to that group’s source files; it does not show which change made those bytes appear or disappear. Code in one group can change another group’s bytes. A new call pulls a library function into the image, link-time optimization (LTO) can inline a function from one group into another group’s code, and removing a caller can let the compiler delete a function elsewhere. When two features share a helper function, the cost of one depends on whether the other is present, so no single number is the whole cost of either.
The chart is still a correct description when the groups are disjoint, cover every byte including padding, and keep their signs, so that the bars add up to the total change. To claim that a module caused a number of bytes, build the program with and without only that module’s change, with the same compiler and options, and compare the totals.
Related entries: Link-time optimization (LTO) (§12.10), Dead-code elimination (§12.11), Static versus dynamic footprint (§11.38), Figure 10a: linker footprint totals and memory categories (§18.2.15), Causal attribution, interventions, and competing explanations (§18.5.15), Alignment (§4.22).