Skip to content

.subsections_via_symbols directive causes invalid symbol pruning in macOS x86-64 kernels #6089

Description

@topolarity
// sasum.c
#include <stdio.h>
#include <cblas.h>
int main(void) {
  float x[5] = {3, -1, 2, -4, 1};
  printf("cblas_sasum = %g\n", cblas_sasum(5, x, 1));   // expect 11
  return 0;
}
$ clang -arch x86_64 -O2 -I$(BUILD_DIR) sasum.c -L$(BUILD_DIR) -lopenblas -Wl,-rpath,$(BUILD_DIR) -o sasum_dyn
$ ./sasum_dyn
cblas_sasum = 4.01598e-36

The correct output is:

$ ./sasum_dyn
cblas_sasum = 11

OpenBLAS built with make TARGET=NEHALEM NOFORTRAN=1 (on Apple Silicon, the full invocation is arch -x86_64 make -j6 ARCH=x86_64 BINARY=64 CC="clang -arch x86_64" HOSTCC="clang -arch x86_64" TARGET=NEHALEM NOFORTRAN=1 shared) with Apple clang 21.0.0

The problem is that even without -Wl,-dead-strip the linker will still try to deduplicate labels unless -Wl,-no_deduplicate is provided explicitly. This happens to .L998 and .L999 in the sasum_k kernel.

I am testing via Rosetta on AArch64 macOS hardware, but I suspect this reproduces on proper x86-64 macOS targets.

Activity

  1. topolarity commented on Oct 2, 2026

    @topolarity
    Author

    Looks like this problem is specific to Apple's new linker from 2023. Building with -Wl,-ld_classic also works around the issue.

  2. martin-frbg commented on Oct 2, 2026

    @martin-frbg
    Collaborator

    Not sure what to make of this - your PRs look way too invasive for what may well be a bug in a specific linker version on an obsolescent target that (if I understand you correctly) gets triggered only by very specific non-default build options.

  3. topolarity commented on Oct 2, 2026

    @topolarity
    Author

    your PRs look way too invasive

    Agreed. The PRs are much bigger and more invasive than I would like...

    I hope I can clarify the motivation. The goal for #6088 / #6087 is to allow the linker to remove unused code - #6090 is only needed to enable code pruning on macOS.

    a bug in a specific linker version on an obsolescent target

    x86_64-darwin happens to trigger this issue w/o dead-strip, but the problem is broader than that. The issue here happens as soon as you enable .subsections_via_symbols with a new enough clang, on any macOS target AFAIK and so dead-strip breaks OpenBLAS on macOS (incl. arm64) without #6090

    The first two PRs apply to all platforms (--Wl,--gc-sections on Linux / MinGW + -Wl,-dead-strip on macOS) and they are trying to allow the linker to strip code under DYNAMIC_ARCH. Without them, gotoblas references all kernels even if you e.g. only rely on dgemm.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions