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

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