[PATCH] D76665: [asan] Stop instrumenting user-defined ELF sections

Michał Górny via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 15 04:19:07 PDT 2020


mgorny updated this revision to Diff 270713.
mgorny retitled this revision from "[asan] Stop instrumenting NetBSD-specific link_set sections" to "[asan] Stop instrumenting user-defined ELF sections".
mgorny edited the summary of this revision.
mgorny added a comment.

Is this what you had in mind? I'm sorry it took me this long to get to it again.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76665/new/

https://reviews.llvm.org/D76665

Files:
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/do-not-instrument-netbsd-link_set.ll


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"
+
+ at data1 = dso_local global i32 1, align 4
+ at data2 = dso_local global i32 2, align 4
+ at __link_set_test_set_sym_data1 = internal constant i8* bitcast (i32* @data1 to i8*), section "link_set_test_set", align 8
+ at __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"
Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1876,6 +1876,14 @@
       return false;
     }
 
+    // Do not instrument user-defined sections (with names resembling
+    // valid C identifiers)
+    if (TargetTriple.isOSBinFormatELF()) {
+      if (std::all_of(Section.begin(), Section.end(),
+                      [](char c) { return llvm::isAlnum(c) || c == '_'; }))
+        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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76665.270713.patch
Type: text/x-patch
Size: 1939 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200615/50bc8a49/attachment.bin>


More information about the llvm-commits mailing list