Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1853,6 +1853,15 @@ return false; } + // Do not instrument NetBSD and NetBSD-derived (such as rumpkernel) code + // sections dedicated for the __link_set API that expects consecutive + // array elements + if (Section.startswith("link_set")) { + LLVM_DEBUG(dbgs() << "Ignoring global in sorted section " + << "(starts with 'link_set'): " << *G << "\n"); + return false; + } + // On COFF, if the section name contains '$', it is highly likely that the // user is using section sorting to create an array of globals similar to // the way initialization callbacks are registered in .init_array and Index: llvm/test/Instrumentation/AddressSanitizer/do-not-instrument-netbsd-link_set.ll =================================================================== --- /dev/null +++ llvm/test/Instrumentation/AddressSanitizer/do-not-instrument-netbsd-link_set.ll @@ -0,0 +1,14 @@ +; This test checks that NetBSD link_set array elements remain consecutive. +; RUN: opt < %s -asan -asan-module -S | FileCheck %s + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-netbsd" + +module asm ".hidden __stop_link_set_test_set" + +@data1 = dso_local global i32 1, align 4 +@data2 = dso_local global i32 2, align 4 +@__link_set_test_set_sym_data1 = internal constant i8* bitcast (i32* @data1 to i8*), section "link_set_test_set", align 8 +@__link_set_test_set_sym_data2 = internal constant i8* bitcast (i32* @data2 to i8*), section "link_set_test_set", align 8 +; CHECK: @__link_set_test_set_sym_data1 = internal constant i8*{{.*}}, section "link_set_test_set" +; CHECK-NEXT: @__link_set_test_set_sym_data2 = internal constant i8*{{.*}}, section "link_set_test_set"