Skip to content

Build reproducibility issue related to STT_FILE symbols #2959

Closed

Description

@miyuki

We are facing a reproducibility issue when building static archives (.a) that include empty translation units. In our build, some files are completely ifdef-ed out, so the preprocessor output is identical for different input files. The compiler embeds the source file's basename as an STT_FILE symbol into the object file, so we get different object files for those input files. In a build with sccache, the first cached object file gets reused.

The issue reproduces with sccache 0.19.0 on x86-64 Linux (Ubuntu 24.04 LTS).

Reproducer:

alpha.c:

#ifdef ENABLE_OPTIONAL_CODE
int alpha(void) { return 1; }
#endif

beta.c:

#ifdef ENABLE_OPTIONAL_CODE
int beta(void) { return 2; }
#endif

reproduce.sh:

#!/bin/sh

cache=$(mktemp -d)
export SCCACHE_SERVER_UDS="$cache/server.sock"
export SCCACHE_DIRECT=false
export SCCACHE_DIR="$cache"

clang -c alpha.c -o alpha.o
clang -c beta.c -o beta.o
ar rcs noncached.a alpha.o beta.o
readelf -sW noncached.a

sccache clang -c alpha.c -o cached-alpha.o
sccache clang -c beta.c -o cached-beta.o
ar rcs cached.a cached-alpha.o cached-beta.o
readelf -sW cached.a

sccache --stop-server >/dev/null

The output of reproduce.sh is as follows:

File: noncached.a(alpha.o)

Symbol table '.symtab' contains 2 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS alpha.c

File: noncached.a(beta.o)

Symbol table '.symtab' contains 2 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS beta.c

File: cached.a(cached-alpha.o)

Symbol table '.symtab' contains 2 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS alpha.c

File: cached.a(cached-beta.o)

Symbol table '.symtab' contains 2 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS alpha.c

For the non-cached build, the FILE entries (STT_FILE symbols) are as expected: alpha.c, beta.c. For the cached build we have alpha.c twice. Due to concurrency in real builds, the file that gets cached first varies from build to build.

STT_FILE isn't quite debug info, so please consider including the source path basename (not necessarily the full path - STT_FILE is based on the basename) in the cache key.

Activity

  1. added a commit that references this issue on Nov 3, 2026
    5808192
  2. added a commit that references this issue on Nov 22, 2026
    468c7a1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions