llvm-project/compiler-rt/test/metadata/nocallback.cpp
Marco Elver 5265adc737 [SanitizerBinaryMetadata] Declare callbacks extern weak
Declare callbacks extern weak (if no existing declaration exists), and
only call if the function address is non-null.

This allows to attach semantic metadata to binaries where no user of
that metadata exists, avoiding to have to link empty stub callbacks.

Once the binary is linked (statically or dynamically) against a tool
runtime that implements the callbacks, the respective callbacks will be
called. This vastly simplifies gradual deployment of tools using the
metadata, esp. avoiding having to recompile large codebases with
different compiler flags (which negatively impacts compiler caches).

Reviewed By: dvyukov, vitalybuka

Differential Revision: https://reviews.llvm.org/D142408
2023-01-24 12:54:20 +01:00

14 lines
283 B
C++

// RUN: %clangxx %s -o %t -fexperimental-sanitize-metadata=all && %t | FileCheck %s
// Test that the compiler emits weak declarations to the callbacks, which are
// not called if they do not exist.
#include <stdio.h>
int main() {
printf("main\n");
return 0;
}
// CHECK: main