[PATCH] D62005: [libunwind] [test] Fix inferring source paths

2019-05-16 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: jroelofs, krytarowski.
Herald added subscribers: libcxx-commits, ldionne, christof.

Fix two issues that caused libcxx source path not to be inferred
correctly when not specified explicitly:

1. get_lit_conf() uses default value only if the lit variable is set to None.  
Due to the mehod of substituting lit.site.cfg, they were "" rather than None 
when unset, effectively causing the default never to apply.  Instead, use 'or' 
construct to use the default whenever get_lit_conf() returns a false value.

2. If os.path.join() is given a component starting with '/', it takes it to be 
an absolute path and ignores everything preceding it. Remove the slash to 
correctly append subdirectory.

With these two fixes, libunwind tests start working on NetBSD buildbot
again.


Repository:
  rUNW libunwind

https://reviews.llvm.org/D62005

Files:
  libunwind/test/libunwind/test/config.py


Index: libunwind/test/libunwind/test/config.py
===
--- libunwind/test/libunwind/test/config.py
+++ libunwind/test/libunwind/test/config.py
@@ -21,12 +21,10 @@
 self.libcxx_src_root = None
 
 def configure_src_root(self):
-self.libunwind_src_root = self.get_lit_conf(
-'libunwind_src_root',
-os.path.dirname(self.config.test_source_root))
-self.libcxx_src_root = self.get_lit_conf(
-'libcxx_src_root',
-os.path.join(self.libunwind_src_root, '/../libcxx'))
+self.libunwind_src_root = (self.get_lit_conf('libunwind_src_root')
+or os.path.dirname(self.config.test_source_root))
+self.libcxx_src_root = (self.get_lit_conf('libcxx_src_root')
+or os.path.join(self.libunwind_src_root, '../libcxx'))
 
 def configure_obj_root(self):
 self.libunwind_obj_root = self.get_lit_conf('libunwind_obj_root')


Index: libunwind/test/libunwind/test/config.py
===
--- libunwind/test/libunwind/test/config.py
+++ libunwind/test/libunwind/test/config.py
@@ -21,12 +21,10 @@
 self.libcxx_src_root = None
 
 def configure_src_root(self):
-self.libunwind_src_root = self.get_lit_conf(
-'libunwind_src_root',
-os.path.dirname(self.config.test_source_root))
-self.libcxx_src_root = self.get_lit_conf(
-'libcxx_src_root',
-os.path.join(self.libunwind_src_root, '/../libcxx'))
+self.libunwind_src_root = (self.get_lit_conf('libunwind_src_root')
+or os.path.dirname(self.config.test_source_root))
+self.libcxx_src_root = (self.get_lit_conf('libcxx_src_root')
+or os.path.join(self.libunwind_src_root, '../libcxx'))
 
 def configure_obj_root(self):
 self.libunwind_obj_root = self.get_lit_conf('libunwind_obj_root')
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62005: [libunwind] [test] Fix inferring source paths

2019-05-22 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Ping.


Repository:
  rUNW libunwind

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

https://reviews.llvm.org/D62005



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62005: [libunwind] [test] Fix inferring source paths

2019-05-28 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Ping. Could somebody review this, please? It's blocking NetBSD buildbot for 
quite some time already.


Repository:
  rUNW libunwind

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

https://reviews.llvm.org/D62005



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62005: [libunwind] [test] Fix inferring source paths

2019-05-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny marked 2 inline comments as done.
mgorny added inline comments.



Comment at: libunwind/test/libunwind/test/config.py:27
+self.libcxx_src_root = (self.get_lit_conf('libcxx_src_root')
+or os.path.join(self.libunwind_src_root, '../libcxx'))
 

phosek wrote:
> Can you use `os.path.join(self.libunwind_src_root, '..', 'libcxx')` to make 
> it compatible with systems that don't use `/` as path separators?
Good catch. Will do.


Repository:
  rUNW libunwind

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

https://reviews.llvm.org/D62005



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62005: [libunwind] [test] Fix inferring source paths

2019-05-29 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
mgorny marked an inline comment as done.
Closed by commit rL361931: [libunwind] [test] Fix inferring source paths 
(authored by mgorny, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62005?vs=199799&id=201834#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D62005

Files:
  libunwind/trunk/test/libunwind/test/config.py


Index: libunwind/trunk/test/libunwind/test/config.py
===
--- libunwind/trunk/test/libunwind/test/config.py
+++ libunwind/trunk/test/libunwind/test/config.py
@@ -21,12 +21,10 @@
 self.libcxx_src_root = None
 
 def configure_src_root(self):
-self.libunwind_src_root = self.get_lit_conf(
-'libunwind_src_root',
-os.path.dirname(self.config.test_source_root))
-self.libcxx_src_root = self.get_lit_conf(
-'libcxx_src_root',
-os.path.join(self.libunwind_src_root, '/../libcxx'))
+self.libunwind_src_root = (self.get_lit_conf('libunwind_src_root')
+or os.path.dirname(self.config.test_source_root))
+self.libcxx_src_root = (self.get_lit_conf('libcxx_src_root')
+or os.path.join(self.libunwind_src_root, '..', 'libcxx'))
 
 def configure_obj_root(self):
 self.libunwind_obj_root = self.get_lit_conf('libunwind_obj_root')


Index: libunwind/trunk/test/libunwind/test/config.py
===
--- libunwind/trunk/test/libunwind/test/config.py
+++ libunwind/trunk/test/libunwind/test/config.py
@@ -21,12 +21,10 @@
 self.libcxx_src_root = None
 
 def configure_src_root(self):
-self.libunwind_src_root = self.get_lit_conf(
-'libunwind_src_root',
-os.path.dirname(self.config.test_source_root))
-self.libcxx_src_root = self.get_lit_conf(
-'libcxx_src_root',
-os.path.join(self.libunwind_src_root, '/../libcxx'))
+self.libunwind_src_root = (self.get_lit_conf('libunwind_src_root')
+or os.path.dirname(self.config.test_source_root))
+self.libcxx_src_root = (self.get_lit_conf('libcxx_src_root')
+or os.path.join(self.libunwind_src_root, '..', 'libcxx'))
 
 def configure_obj_root(self):
 self.libunwind_obj_root = self.get_lit_conf('libunwind_obj_root')
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55654: [clang] [Driver] [NetBSD] Add -D_REENTRANT when using sanitizers

2018-12-13 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka, joerg, bkramer.
Herald added subscribers: jfb, cryptoad.

Requested by @krytarowski with the following rationale:

  We intend to support only reentrant interfaces in interceptors and if
  we use -lpthread without _REENTRANT defined, things are not guaranteed
  to work. This defined _REENTRANT is especially important for 
  and sanitization of interfaces around struct FILE. Some APIs have
  alternative modes depending on whether there is _REENTRANT enabled in
  the preprocessor namespace. We intend to sanitize only the _REENTRANT
  ones.


Repository:
  rC Clang

https://reviews.llvm.org/D55654

Files:
  lib/Driver/ToolChains/NetBSD.cpp
  lib/Driver/ToolChains/NetBSD.h


Index: lib/Driver/ToolChains/NetBSD.h
===
--- lib/Driver/ToolChains/NetBSD.h
+++ lib/Driver/ToolChains/NetBSD.h
@@ -76,6 +76,10 @@
 
   SanitizerMask getSupportedSanitizers() const override;
 
+  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args,
+ Action::OffloadKind DeviceOffloadKind) const 
override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
Index: lib/Driver/ToolChains/NetBSD.cpp
===
--- lib/Driver/ToolChains/NetBSD.cpp
+++ lib/Driver/ToolChains/NetBSD.cpp
@@ -457,3 +457,18 @@
   }
   return Res;
 }
+
+void NetBSD::addClangTargetOptions(const ArgList &,
+   ArgStringList &CC1Args,
+   Action::OffloadKind) const {
+  const SanitizerArgs &SanArgs = getSanitizerArgs();
+  if (SanArgs.needsAsanRt() || SanArgs.needsHwasanRt() ||
+  SanArgs.needsDfsanRt() || SanArgs.needsLsanRt() ||
+  SanArgs.needsMsanRt() || SanArgs.needsTsanRt() ||
+  SanArgs.needsUbsanRt() || SanArgs.needsSafeStackRt() ||
+  SanArgs.needsCfiRt() || SanArgs.needsCfiDiagRt() ||
+  SanArgs.needsStatsRt() || SanArgs.needsEsanRt() ||
+  SanArgs.needsScudoRt()) {
+CC1Args.push_back("-D_REENTRANT");
+  }
+}


Index: lib/Driver/ToolChains/NetBSD.h
===
--- lib/Driver/ToolChains/NetBSD.h
+++ lib/Driver/ToolChains/NetBSD.h
@@ -76,6 +76,10 @@
 
   SanitizerMask getSupportedSanitizers() const override;
 
+  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args,
+ Action::OffloadKind DeviceOffloadKind) const override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
Index: lib/Driver/ToolChains/NetBSD.cpp
===
--- lib/Driver/ToolChains/NetBSD.cpp
+++ lib/Driver/ToolChains/NetBSD.cpp
@@ -457,3 +457,18 @@
   }
   return Res;
 }
+
+void NetBSD::addClangTargetOptions(const ArgList &,
+   ArgStringList &CC1Args,
+   Action::OffloadKind) const {
+  const SanitizerArgs &SanArgs = getSanitizerArgs();
+  if (SanArgs.needsAsanRt() || SanArgs.needsHwasanRt() ||
+  SanArgs.needsDfsanRt() || SanArgs.needsLsanRt() ||
+  SanArgs.needsMsanRt() || SanArgs.needsTsanRt() ||
+  SanArgs.needsUbsanRt() || SanArgs.needsSafeStackRt() ||
+  SanArgs.needsCfiRt() || SanArgs.needsCfiDiagRt() ||
+  SanArgs.needsStatsRt() || SanArgs.needsEsanRt() ||
+  SanArgs.needsScudoRt()) {
+CC1Args.push_back("-D_REENTRANT");
+  }
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55657: [libcxx] [regex] Use distinct __regex_word on NetBSD

2018-12-13 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, howard.hinnant, dsanders, EricWF.
Herald added subscribers: libcxx-commits, ldionne.

NetBSD defines character classes up to 0x2000.  Use 0x8000 as a safe
__regex_word that hopefully will not collide with other values
in the foreseeable future.


Repository:
  rCXX libc++

https://reviews.llvm.org/D55657

Files:
  include/regex


Index: include/regex
===
--- include/regex
+++ include/regex
@@ -990,6 +990,9 @@
 
 #if defined(__mips__) && defined(__GLIBC__)
 static const char_class_type __regex_word = 
static_cast(_ISbit(15));
+#elif defined(__NetBSD__)
+// NetBSD defines classes up to 0x2000
+static const char_class_type __regex_word = 0x8000;
 #else
 static const char_class_type __regex_word = 0x80;
 #endif


Index: include/regex
===
--- include/regex
+++ include/regex
@@ -990,6 +990,9 @@
 
 #if defined(__mips__) && defined(__GLIBC__)
 static const char_class_type __regex_word = static_cast(_ISbit(15));
+#elif defined(__NetBSD__)
+// NetBSD defines classes up to 0x2000
+static const char_class_type __regex_word = 0x8000;
 #else
 static const char_class_type __regex_word = 0x80;
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55657: [libcxx] [regex] Use distinct __regex_word on NetBSD

2018-12-13 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 178113.

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

https://reviews.llvm.org/D55657

Files:
  include/regex


Index: include/regex
===
--- include/regex
+++ include/regex
@@ -990,6 +990,10 @@
 
 #if defined(__mips__) && defined(__GLIBC__)
 static const char_class_type __regex_word = 
static_cast(_ISbit(15));
+#elif defined(__NetBSD__)
+// NetBSD defines classes up to 0x2000
+// see sys/ctype_bits.h, _CTYPE_Q
+static const char_class_type __regex_word = 0x8000;
 #else
 static const char_class_type __regex_word = 0x80;
 #endif


Index: include/regex
===
--- include/regex
+++ include/regex
@@ -990,6 +990,10 @@
 
 #if defined(__mips__) && defined(__GLIBC__)
 static const char_class_type __regex_word = static_cast(_ISbit(15));
+#elif defined(__NetBSD__)
+// NetBSD defines classes up to 0x2000
+// see sys/ctype_bits.h, _CTYPE_Q
+static const char_class_type __regex_word = 0x8000;
 #else
 static const char_class_type __regex_word = 0x80;
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55443: [test] Capture stderr from 'tar --version' call as well

2018-12-14 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349204: [test] Capture stderr from 'tar --version' 
call as well (authored by mgorny, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55443?vs=177265&id=178296#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55443

Files:
  lld/trunk/test/lit.cfg.py


Index: lld/trunk/test/lit.cfg.py
===
--- lld/trunk/test/lit.cfg.py
+++ lld/trunk/test/lit.cfg.py
@@ -94,7 +94,10 @@
 tar_executable = lit.util.which('tar', config.environment['PATH'])
 if tar_executable:
 tar_version = subprocess.Popen(
-[tar_executable, '--version'], stdout=subprocess.PIPE, env={'LANG': 
'C'})
-if 'GNU tar' in tar_version.stdout.read().decode():
+[tar_executable, '--version'],
+stdout=subprocess.PIPE,
+stderr=subprocess.PIPE,
+env={'LANG': 'C'})
+sout, _ = tar_version.communicate()
+if 'GNU tar' in sout.decode():
 config.available_features.add('gnutar')
-tar_version.wait()


Index: lld/trunk/test/lit.cfg.py
===
--- lld/trunk/test/lit.cfg.py
+++ lld/trunk/test/lit.cfg.py
@@ -94,7 +94,10 @@
 tar_executable = lit.util.which('tar', config.environment['PATH'])
 if tar_executable:
 tar_version = subprocess.Popen(
-[tar_executable, '--version'], stdout=subprocess.PIPE, env={'LANG': 'C'})
-if 'GNU tar' in tar_version.stdout.read().decode():
+[tar_executable, '--version'],
+stdout=subprocess.PIPE,
+stderr=subprocess.PIPE,
+env={'LANG': 'C'})
+sout, _ = tar_version.communicate()
+if 'GNU tar' in sout.decode():
 config.available_features.add('gnutar')
-tar_version.wait()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55657: [libcxx] [regex] Use distinct __regex_word on NetBSD

2018-12-16 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349293: [regex] Use distinct __regex_word on NetBSD 
(authored by mgorny, committed by ).
Herald added subscribers: llvm-commits, christof.

Changed prior to commit:
  https://reviews.llvm.org/D55657?vs=178113&id=178387#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55657

Files:
  libcxx/trunk/include/regex


Index: libcxx/trunk/include/regex
===
--- libcxx/trunk/include/regex
+++ libcxx/trunk/include/regex
@@ -990,6 +990,10 @@
 
 #if defined(__mips__) && defined(__GLIBC__)
 static const char_class_type __regex_word = 
static_cast(_ISbit(15));
+#elif defined(__NetBSD__)
+// NetBSD defines classes up to 0x2000
+// see sys/ctype_bits.h, _CTYPE_Q
+static const char_class_type __regex_word = 0x8000;
 #else
 static const char_class_type __regex_word = 0x80;
 #endif


Index: libcxx/trunk/include/regex
===
--- libcxx/trunk/include/regex
+++ libcxx/trunk/include/regex
@@ -990,6 +990,10 @@
 
 #if defined(__mips__) && defined(__GLIBC__)
 static const char_class_type __regex_word = static_cast(_ISbit(15));
+#elif defined(__NetBSD__)
+// NetBSD defines classes up to 0x2000
+// see sys/ctype_bits.h, _CTYPE_Q
+static const char_class_type __regex_word = 0x8000;
 #else
 static const char_class_type __regex_word = 0x80;
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55576: [libcxx] [test] [support] Use socket()+bind() to create unix sockets portably

2018-12-16 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a reviewer: emaste.
mgorny added a comment.

@emaste, maybe you could take a look at this too. I think it would solve the 
problem for FreeBSD as well.


Repository:
  rCXX libc++

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

https://reviews.llvm.org/D55576



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55576: [libcxx] [test] [support] Use socket()+bind() to create unix sockets portably

2018-12-16 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCXX349305: [test] [support] Use socket()+bind() to create 
unix sockets portably (authored by mgorny, committed by ).

Repository:
  rCXX libc++

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

https://reviews.llvm.org/D55576

Files:
  test/support/filesystem_dynamic_test_helper.py


Index: test/support/filesystem_dynamic_test_helper.py
===
--- test/support/filesystem_dynamic_test_helper.py
+++ test/support/filesystem_dynamic_test_helper.py
@@ -1,5 +1,6 @@
 import sys
 import os
+import socket
 import stat
 
 # Ensure that this is being run on a specific platform
@@ -76,8 +77,13 @@
 
 
 def create_socket(source):
-mode = 0o600 | stat.S_IFSOCK
-os.mknod(sanitize(source), mode)
+sock = socket.socket(socket.AF_UNIX)
+sanitized_source = sanitize(source)
+# AF_UNIX sockets may have very limited path length, so split it
+# into chdir call (with technically unlimited length) followed
+# by bind() relative to the directory
+os.chdir(os.path.dirname(sanitized_source))
+sock.bind(os.path.basename(sanitized_source))
 
 
 if __name__ == '__main__':


Index: test/support/filesystem_dynamic_test_helper.py
===
--- test/support/filesystem_dynamic_test_helper.py
+++ test/support/filesystem_dynamic_test_helper.py
@@ -1,5 +1,6 @@
 import sys
 import os
+import socket
 import stat
 
 # Ensure that this is being run on a specific platform
@@ -76,8 +77,13 @@
 
 
 def create_socket(source):
-mode = 0o600 | stat.S_IFSOCK
-os.mknod(sanitize(source), mode)
+sock = socket.socket(socket.AF_UNIX)
+sanitized_source = sanitize(source)
+# AF_UNIX sockets may have very limited path length, so split it
+# into chdir call (with technically unlimited length) followed
+# by bind() relative to the directory
+os.chdir(os.path.dirname(sanitized_source))
+sock.bind(os.path.basename(sanitized_source))
 
 
 if __name__ == '__main__':
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55576: [libcxx] [test] [support] Use socket()+bind() to create unix sockets portably

2018-12-16 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

@dim, thanks for the review. Should I also try removing the following 
restriction?

  #if !defined(__APPLE__) && !defined(__FreeBSD__) // No support for domain 
sockets
  {env.create_socket("socket"), file_type::socket},
  #endif


Repository:
  rCXX libc++

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

https://reviews.llvm.org/D55576



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55811: [compiler-rt] [sanitizer_common] Fix sha2 interceptors not to use vars in array len

2018-12-18 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, dberris, kubamracek.

Fix the sha2 interceptor macros to use a constant for array parameter
length rather than referencing the extern variable.  Since the digest
length is provided in hash name, reuse the macro parameter for it.
Verify that the calculated value matches the one provided by system
headers.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D55811

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc


Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -8435,9 +8435,10 @@
 if (context) \
   COMMON_INTERCEPTOR_WRITE_RANGE(ctx, context, SHA##LEN##_CTX_sz); \
   } \
-  INTERCEPTOR(void, SHA##LEN##_Final, u8 digest[SHA##LEN##_digest_length], \
+  INTERCEPTOR(void, SHA##LEN##_Final, u8 digest[LEN/8], \
   void *context) { \
 void *ctx; \
+CHECK_EQ(SHA##LEN##_digest_length, LEN/8); \
 COMMON_INTERCEPTOR_ENTER(ctx, SHA##LEN##_Final, digest, context); \
 if (context) \
   COMMON_INTERCEPTOR_READ_RANGE(ctx, context, SHA##LEN##_CTX_sz); \


Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -8435,9 +8435,10 @@
 if (context) \
   COMMON_INTERCEPTOR_WRITE_RANGE(ctx, context, SHA##LEN##_CTX_sz); \
   } \
-  INTERCEPTOR(void, SHA##LEN##_Final, u8 digest[SHA##LEN##_digest_length], \
+  INTERCEPTOR(void, SHA##LEN##_Final, u8 digest[LEN/8], \
   void *context) { \
 void *ctx; \
+CHECK_EQ(SHA##LEN##_digest_length, LEN/8); \
 COMMON_INTERCEPTOR_ENTER(ctx, SHA##LEN##_Final, digest, context); \
 if (context) \
   COMMON_INTERCEPTOR_READ_RANGE(ctx, context, SHA##LEN##_CTX_sz); \
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55828: [clang] [Driver] Disable -faddrsig by default on NetBSD

2018-12-18 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, pcc.

Avoid passing -faddrsig by default on NetBSD.  This platform is still
using old GNU binutils that crashes on executables containing those
sections.


Repository:
  rC Clang

https://reviews.llvm.org/D55828

Files:
  lib/Driver/ToolChains/Clang.cpp


Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -5272,7 +5272,8 @@
   if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,
(TC.getTriple().isOSBinFormatELF() ||
 TC.getTriple().isOSBinFormatCOFF()) &&
-   TC.useIntegratedAs()))
+   TC.useIntegratedAs() &&
+   RawTriple.getOS() != llvm::Triple::NetBSD))
 CmdArgs.push_back("-faddrsig");
 
   // Finally add the compile command to the compilation.


Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -5272,7 +5272,8 @@
   if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,
(TC.getTriple().isOSBinFormatELF() ||
 TC.getTriple().isOSBinFormatCOFF()) &&
-   TC.useIntegratedAs()))
+   TC.useIntegratedAs() &&
+   RawTriple.getOS() != llvm::Triple::NetBSD))
 CmdArgs.push_back("-faddrsig");
 
   // Finally add the compile command to the compilation.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55830: [clang] [Basic] Correct description of SanitizerSet.empty()

2018-12-18 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: bkramer, samsonov, krytarowski.

It seems to have gotten inverted.


Repository:
  rC Clang

https://reviews.llvm.org/D55830

Files:
  include/clang/Basic/Sanitizers.h


Index: include/clang/Basic/Sanitizers.h
===
--- include/clang/Basic/Sanitizers.h
+++ include/clang/Basic/Sanitizers.h
@@ -66,7 +66,7 @@
   /// Disable the sanitizers specified in \p K.
   void clear(SanitizerMask K = SanitizerKind::All) { Mask &= ~K; }
 
-  /// Returns true if at least one sanitizer is enabled.
+  /// Returns true if no sanitizers are enabled.
   bool empty() const { return Mask == 0; }
 
   /// Bitmask of enabled sanitizers.


Index: include/clang/Basic/Sanitizers.h
===
--- include/clang/Basic/Sanitizers.h
+++ include/clang/Basic/Sanitizers.h
@@ -66,7 +66,7 @@
   /// Disable the sanitizers specified in \p K.
   void clear(SanitizerMask K = SanitizerKind::All) { Mask &= ~K; }
 
-  /// Returns true if at least one sanitizer is enabled.
+  /// Returns true if no sanitizers are enabled.
   bool empty() const { return Mask == 0; }
 
   /// Bitmask of enabled sanitizers.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55832: [clang] [Driver] Add .hasAnySanitizer() to SanitizerArgs

2018-12-18 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka, samsonov, pcc.

Add a simple method to query whether any sanitizer was enabled,
via SanitizerArgs.  This will be used in the NetBSD driver to pass
additional definitions that are required by all sanitizers.


Repository:
  rC Clang

https://reviews.llvm.org/D55832

Files:
  include/clang/Driver/SanitizerArgs.h


Index: include/clang/Driver/SanitizerArgs.h
===
--- include/clang/Driver/SanitizerArgs.h
+++ include/clang/Driver/SanitizerArgs.h
@@ -82,6 +82,7 @@
   bool needsUnwindTables() const;
   bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
   bool hasCrossDsoCfi() const { return CfiCrossDso; }
+  bool hasAnySanitizer() const { return !Sanitizers.empty(); }
   void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
 };


Index: include/clang/Driver/SanitizerArgs.h
===
--- include/clang/Driver/SanitizerArgs.h
+++ include/clang/Driver/SanitizerArgs.h
@@ -82,6 +82,7 @@
   bool needsUnwindTables() const;
   bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
   bool hasCrossDsoCfi() const { return CfiCrossDso; }
+  bool hasAnySanitizer() const { return !Sanitizers.empty(); }
   void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55654: [clang] [Driver] [NetBSD] Add -D_REENTRANT when using sanitizers

2018-12-18 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 178701.
mgorny edited the summary of this revision.

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

https://reviews.llvm.org/D55654

Files:
  lib/Driver/ToolChains/NetBSD.cpp
  lib/Driver/ToolChains/NetBSD.h


Index: lib/Driver/ToolChains/NetBSD.h
===
--- lib/Driver/ToolChains/NetBSD.h
+++ lib/Driver/ToolChains/NetBSD.h
@@ -76,6 +76,10 @@
 
   SanitizerMask getSupportedSanitizers() const override;
 
+  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args,
+ Action::OffloadKind DeviceOffloadKind) const 
override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
Index: lib/Driver/ToolChains/NetBSD.cpp
===
--- lib/Driver/ToolChains/NetBSD.cpp
+++ lib/Driver/ToolChains/NetBSD.cpp
@@ -457,3 +457,11 @@
   }
   return Res;
 }
+
+void NetBSD::addClangTargetOptions(const ArgList &,
+   ArgStringList &CC1Args,
+   Action::OffloadKind) const {
+  const SanitizerArgs &SanArgs = getSanitizerArgs();
+  if (SanArgs.hasAnySanitizer())
+CC1Args.push_back("-D_REENTRANT");
+}


Index: lib/Driver/ToolChains/NetBSD.h
===
--- lib/Driver/ToolChains/NetBSD.h
+++ lib/Driver/ToolChains/NetBSD.h
@@ -76,6 +76,10 @@
 
   SanitizerMask getSupportedSanitizers() const override;
 
+  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args,
+ Action::OffloadKind DeviceOffloadKind) const override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
Index: lib/Driver/ToolChains/NetBSD.cpp
===
--- lib/Driver/ToolChains/NetBSD.cpp
+++ lib/Driver/ToolChains/NetBSD.cpp
@@ -457,3 +457,11 @@
   }
   return Res;
 }
+
+void NetBSD::addClangTargetOptions(const ArgList &,
+   ArgStringList &CC1Args,
+   Action::OffloadKind) const {
+  const SanitizerArgs &SanArgs = getSanitizerArgs();
+  if (SanArgs.hasAnySanitizer())
+CC1Args.push_back("-D_REENTRANT");
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55654: [clang] [Driver] [NetBSD] Add -D_REENTRANT when using sanitizers

2018-12-18 Thread Michał Górny via Phabricator via cfe-commits
mgorny marked 2 inline comments as done.
mgorny added inline comments.



Comment at: lib/Driver/ToolChains/NetBSD.cpp:465
+  const SanitizerArgs &SanArgs = getSanitizerArgs();
+  if (SanArgs.needsAsanRt() || SanArgs.needsHwasanRt() ||
+  SanArgs.needsDfsanRt() || SanArgs.needsLsanRt() ||

krytarowski wrote:
> There should be some way to express any sanitizer (-fsanitize) and we want 
> _REENTRANT for all of them.
I've added it in dependent commit.


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

https://reviews.llvm.org/D55654



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55891: [compiler-rt] [xray] [tests] Detect and handle missing LLVMTestingSupport gracefully

2018-12-19 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, dberris, george.karpenkov.
Herald added subscribers: Sanitizers, llvm-commits.

Add a code to properly test for presence of LLVMTestingSupport library
when performing a stand-alone build, and skip tests requiring it when
it is not present.  Since the library is not installed, llvm-config
reported empty --libs for it and the tests failed to link with undefined
references.  Skipping the two fdr_* test files is better than failing to
build, and should be good enough until we find a better solution.

NB: both installing LLVMTestingSupport and building it automatically
from within compiler-rt sources are non-trivial.  The former due to
dependency on gtest, the latter due to tight integration with LLVM
source tree.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D55891

Files:
  cmake/Modules/CompilerRTUtils.cmake
  lib/xray/tests/CMakeLists.txt
  lib/xray/tests/unit/CMakeLists.txt


Index: lib/xray/tests/unit/CMakeLists.txt
===
--- lib/xray/tests/unit/CMakeLists.txt
+++ lib/xray/tests/unit/CMakeLists.txt
@@ -1,10 +1,16 @@
-add_xray_unittest(XRayTest SOURCES
+set(TEST_SOURCES
   allocator_test.cc
   buffer_queue_test.cc
-  fdr_controller_test.cc
-  fdr_log_writer_test.cc
   function_call_trie_test.cc
   profile_collector_test.cc
   segmented_array_test.cc
   test_helpers.cc
   xray_unit_test_main.cc)
+
+if (NOT COMPILER_RT_STANDALONE_BUILD OR COMPILER_RT_HAS_LLVMTESTINGSUPPORT)
+  list(APPEND TEST_SOURCES
+fdr_controller_test.cc
+fdr_log_writer_test.cc)
+endif()
+
+add_xray_unittest(XRayTest SOURCES ${TEST_SOURCES})
Index: lib/xray/tests/CMakeLists.txt
===
--- lib/xray/tests/CMakeLists.txt
+++ lib/xray/tests/CMakeLists.txt
@@ -60,6 +60,10 @@
   if (COMPILER_RT_STANDALONE_BUILD)
 append_list_if(COMPILER_RT_HAS_LLVMXRAY ${LLVM_XRAY_LDFLAGS} 
XRAY_UNITTEST_LINK_FLAGS)
 append_list_if(COMPILER_RT_HAS_LLVMXRAY ${LLVM_XRAY_LIBLIST} 
XRAY_UNITTEST_LINK_FLAGS)
+append_list_if(COMPILER_RT_HAS_LLVMTESTINGSUPPORT
+  ${LLVM_TESTINGSUPPORT_LDFLAGS} XRAY_UNITTEST_LINK_FLAGS)
+append_list_if(COMPILER_RT_HAS_LLVMTESTINGSUPPORT
+  ${LLVM_TESTINGSUPPORT_LIBLIST} XRAY_UNITTEST_LINK_FLAGS)
   else()
 # We add the library directories one at a time in our CFLAGS.
 foreach (DIR ${LLVM_LIBRARY_DIR})
Index: cmake/Modules/CompilerRTUtils.cmake
===
--- cmake/Modules/CompilerRTUtils.cmake
+++ cmake/Modules/CompilerRTUtils.cmake
@@ -239,7 +239,7 @@
 # Detect if we have the LLVMXRay and TestingSupport library installed and
 # available from llvm-config.
 execute_process(
-  COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "xray" "testingsupport"
+  COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "xray"
   RESULT_VARIABLE HAD_ERROR
   OUTPUT_VARIABLE CONFIG_OUTPUT)
 if (HAD_ERROR)
@@ -254,6 +254,26 @@
   set(COMPILER_RT_HAS_LLVMXRAY TRUE)
 endif()
 
+set(COMPILER_RT_HAS_LLVMTESTINGSUPPORT FALSE)
+execute_process(
+  COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "testingsupport"
+  RESULT_VARIABLE HAD_ERROR
+  OUTPUT_VARIABLE CONFIG_OUTPUT)
+if (HAD_ERROR)
+  message(WARNING "llvm-config finding testingsupport failed with status 
${HAD_ERROR}")
+else()
+  string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" CONFIG_OUTPUT 
${CONFIG_OUTPUT})
+  list(GET CONFIG_OUTPUT 0 LDFLAGS)
+  list(GET CONFIG_OUTPUT 1 LIBLIST)
+  if (LIBLIST STREQUAL "")
+message(WARNING "testingsupport library not installed, some tests will 
be skipped")
+  else()
+set(LLVM_TESTINGSUPPORT_LDFLAGS ${LDFLAGS} CACHE STRING "Linker flags 
for LLVMTestingSupport library")
+set(LLVM_TESTINGSUPPORT_LIBLIST ${LIBLIST} CACHE STRING "Library list 
for LLVMTestingSupport")
+set(COMPILER_RT_HAS_LLVMTESTINGSUPPORT TRUE)
+  endif()
+endif()
+
 # Make use of LLVM CMake modules.
 # --cmakedir is supported since llvm r291218 (4.0 release)
 execute_process(


Index: lib/xray/tests/unit/CMakeLists.txt
===
--- lib/xray/tests/unit/CMakeLists.txt
+++ lib/xray/tests/unit/CMakeLists.txt
@@ -1,10 +1,16 @@
-add_xray_unittest(XRayTest SOURCES
+set(TEST_SOURCES
   allocator_test.cc
   buffer_queue_test.cc
-  fdr_controller_test.cc
-  fdr_log_writer_test.cc
   function_call_trie_test.cc
   profile_collector_test.cc
   segmented_array_test.cc
   test_helpers.cc
   xray_unit_test_main.cc)
+
+if (NOT COMPILER_RT_STANDALONE_BUILD OR COMPILER_RT_HAS_LLVMTESTINGSUPPORT)
+  list(APPEND TEST_SOURCES
+fdr_controller_test.cc
+fdr_log_writer_test.cc)
+endif()
+
+add_xray_unittest(XRayTest SOURCES ${TEST_SOURCES})
Index: lib/xray/tests/CMakeLists.txt
=

[PATCH] D55811: [compiler-rt] [sanitizer_common] Fix sha2 interceptors not to use vars in array len

2018-12-19 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349645: [sanitizer_common] Fix sha2 interceptors not to use 
vars in array len (authored by mgorny, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D55811?vs=178608&id=178897#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55811

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc


Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -8511,9 +8511,10 @@
 if (context) \
   COMMON_INTERCEPTOR_WRITE_RANGE(ctx, context, SHA##LEN##_CTX_sz); \
   } \
-  INTERCEPTOR(void, SHA##LEN##_Final, u8 digest[SHA##LEN##_digest_length], \
+  INTERCEPTOR(void, SHA##LEN##_Final, u8 digest[LEN/8], \
   void *context) { \
 void *ctx; \
+CHECK_EQ(SHA##LEN##_digest_length, LEN/8); \
 COMMON_INTERCEPTOR_ENTER(ctx, SHA##LEN##_Final, digest, context); \
 if (context) \
   COMMON_INTERCEPTOR_READ_RANGE(ctx, context, SHA##LEN##_CTX_sz); \


Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -8511,9 +8511,10 @@
 if (context) \
   COMMON_INTERCEPTOR_WRITE_RANGE(ctx, context, SHA##LEN##_CTX_sz); \
   } \
-  INTERCEPTOR(void, SHA##LEN##_Final, u8 digest[SHA##LEN##_digest_length], \
+  INTERCEPTOR(void, SHA##LEN##_Final, u8 digest[LEN/8], \
   void *context) { \
 void *ctx; \
+CHECK_EQ(SHA##LEN##_digest_length, LEN/8); \
 COMMON_INTERCEPTOR_ENTER(ctx, SHA##LEN##_Final, digest, context); \
 if (context) \
   COMMON_INTERCEPTOR_READ_RANGE(ctx, context, SHA##LEN##_CTX_sz); \
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55828: [clang] [Driver] Disable -faddrsig by default on NetBSD

2018-12-19 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349647: [Driver] Disable -faddrsig by default on NetBSD 
(authored by mgorny, committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D55828

Files:
  lib/Driver/ToolChains/Clang.cpp


Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -5273,7 +5273,8 @@
   if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,
(TC.getTriple().isOSBinFormatELF() ||
 TC.getTriple().isOSBinFormatCOFF()) &&
-   TC.useIntegratedAs()))
+   TC.useIntegratedAs() &&
+   RawTriple.getOS() != llvm::Triple::NetBSD))
 CmdArgs.push_back("-faddrsig");
 
   // Finally add the compile command to the compilation.


Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -5273,7 +5273,8 @@
   if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,
(TC.getTriple().isOSBinFormatELF() ||
 TC.getTriple().isOSBinFormatCOFF()) &&
-   TC.useIntegratedAs()))
+   TC.useIntegratedAs() &&
+   RawTriple.getOS() != llvm::Triple::NetBSD))
 CmdArgs.push_back("-faddrsig");
 
   // Finally add the compile command to the compilation.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55830: [clang] [Basic] Correct description of SanitizerSet.empty()

2018-12-19 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349648: [Basic] Correct description of SanitizerSet.empty() 
(authored by mgorny, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55830?vs=178694&id=178900#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55830

Files:
  cfe/trunk/include/clang/Basic/Sanitizers.h


Index: cfe/trunk/include/clang/Basic/Sanitizers.h
===
--- cfe/trunk/include/clang/Basic/Sanitizers.h
+++ cfe/trunk/include/clang/Basic/Sanitizers.h
@@ -66,7 +66,7 @@
   /// Disable the sanitizers specified in \p K.
   void clear(SanitizerMask K = SanitizerKind::All) { Mask &= ~K; }
 
-  /// Returns true if at least one sanitizer is enabled.
+  /// Returns true if no sanitizers are enabled.
   bool empty() const { return Mask == 0; }
 
   /// Bitmask of enabled sanitizers.


Index: cfe/trunk/include/clang/Basic/Sanitizers.h
===
--- cfe/trunk/include/clang/Basic/Sanitizers.h
+++ cfe/trunk/include/clang/Basic/Sanitizers.h
@@ -66,7 +66,7 @@
   /// Disable the sanitizers specified in \p K.
   void clear(SanitizerMask K = SanitizerKind::All) { Mask &= ~K; }
 
-  /// Returns true if at least one sanitizer is enabled.
+  /// Returns true if no sanitizers are enabled.
   bool empty() const { return Mask == 0; }
 
   /// Bitmask of enabled sanitizers.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55832: [clang] [Driver] Add .hasAnySanitizer() to SanitizerArgs

2018-12-19 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349649: [Driver] Add .hasAnySanitizer() to SanitizerArgs 
(authored by mgorny, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55832?vs=178699&id=178901#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55832

Files:
  cfe/trunk/include/clang/Driver/SanitizerArgs.h


Index: cfe/trunk/include/clang/Driver/SanitizerArgs.h
===
--- cfe/trunk/include/clang/Driver/SanitizerArgs.h
+++ cfe/trunk/include/clang/Driver/SanitizerArgs.h
@@ -82,6 +82,7 @@
   bool needsUnwindTables() const;
   bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
   bool hasCrossDsoCfi() const { return CfiCrossDso; }
+  bool hasAnySanitizer() const { return !Sanitizers.empty(); }
   void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
 };


Index: cfe/trunk/include/clang/Driver/SanitizerArgs.h
===
--- cfe/trunk/include/clang/Driver/SanitizerArgs.h
+++ cfe/trunk/include/clang/Driver/SanitizerArgs.h
@@ -82,6 +82,7 @@
   bool needsUnwindTables() const;
   bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
   bool hasCrossDsoCfi() const { return CfiCrossDso; }
+  bool hasAnySanitizer() const { return !Sanitizers.empty(); }
   void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55654: [clang] [Driver] [NetBSD] Add -D_REENTRANT when using sanitizers

2018-12-19 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
mgorny marked an inline comment as done.
Closed by commit rL349650: [Driver] [NetBSD] Add -D_REENTRANT when using 
sanitizers (authored by mgorny, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55654?vs=178701&id=178902#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55654

Files:
  cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
  cfe/trunk/lib/Driver/ToolChains/NetBSD.h


Index: cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
+++ cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
@@ -457,3 +457,11 @@
   }
   return Res;
 }
+
+void NetBSD::addClangTargetOptions(const ArgList &,
+   ArgStringList &CC1Args,
+   Action::OffloadKind) const {
+  const SanitizerArgs &SanArgs = getSanitizerArgs();
+  if (SanArgs.hasAnySanitizer())
+CC1Args.push_back("-D_REENTRANT");
+}
Index: cfe/trunk/lib/Driver/ToolChains/NetBSD.h
===
--- cfe/trunk/lib/Driver/ToolChains/NetBSD.h
+++ cfe/trunk/lib/Driver/ToolChains/NetBSD.h
@@ -76,6 +76,10 @@
 
   SanitizerMask getSupportedSanitizers() const override;
 
+  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args,
+ Action::OffloadKind DeviceOffloadKind) const 
override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;


Index: cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
+++ cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
@@ -457,3 +457,11 @@
   }
   return Res;
 }
+
+void NetBSD::addClangTargetOptions(const ArgList &,
+   ArgStringList &CC1Args,
+   Action::OffloadKind) const {
+  const SanitizerArgs &SanArgs = getSanitizerArgs();
+  if (SanArgs.hasAnySanitizer())
+CC1Args.push_back("-D_REENTRANT");
+}
Index: cfe/trunk/lib/Driver/ToolChains/NetBSD.h
===
--- cfe/trunk/lib/Driver/ToolChains/NetBSD.h
+++ cfe/trunk/lib/Driver/ToolChains/NetBSD.h
@@ -76,6 +76,10 @@
 
   SanitizerMask getSupportedSanitizers() const override;
 
+  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args,
+ Action::OffloadKind DeviceOffloadKind) const override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55916: [clang] Replace getOS() == llvm::Triple::*BSD with isOS*BSD() [NFCI]

2018-12-20 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added a reviewer: krytarowski.
Herald added subscribers: jsji, atanasyan, jrtc27, fedor.sergeev, kbarton, 
javed.absar, nemanjai, sdardis, emaste, jyknight.

Replace multiple comparisons of getOS() value with FreeBSD, NetBSD,
OpenBSD and DragonFly with matching isOS*BSD() methods.  This should
improve the consistency of coding style without changing the behavior.
Direct getOS() comparisons were left whenever used in switch or switch-
like context.


Repository:
  rC Clang

https://reviews.llvm.org/D55916

Files:
  lib/Basic/Targets/AArch64.cpp
  lib/Basic/Targets/ARM.cpp
  lib/Basic/Targets/Mips.h
  lib/Basic/Targets/PPC.cpp
  lib/Basic/Targets/PPC.h
  lib/Basic/Targets/Sparc.h
  lib/Driver/ToolChains/Arch/Mips.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/CommonArgs.cpp
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/XRayArgs.cpp
  lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp

Index: lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
===
--- lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
+++ lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
@@ -29,10 +29,10 @@
   const llvm::Triple &T = Ctx.getTargetInfo().getTriple();
   return T.getVendor() == llvm::Triple::Apple ||
  T.getOS() == llvm::Triple::CloudABI ||
- T.getOS() == llvm::Triple::FreeBSD ||
- T.getOS() == llvm::Triple::NetBSD ||
- T.getOS() == llvm::Triple::OpenBSD ||
- T.getOS() == llvm::Triple::DragonFly;
+ T.isOSFreeBSD() ||
+ T.isOSNetBSD() ||
+ T.isOSOpenBSD() ||
+ T.isOSDragonFly();
 }
 
 namespace {
Index: lib/Driver/XRayArgs.cpp
===
--- lib/Driver/XRayArgs.cpp
+++ lib/Driver/XRayArgs.cpp
@@ -50,9 +50,9 @@
 D.Diag(diag::err_drv_clang_unsupported)
 << (std::string(XRayInstrumentOption) + " on " + Triple.str());
   }
-} else if (Triple.getOS() == llvm::Triple::FreeBSD ||
-   Triple.getOS() == llvm::Triple::OpenBSD ||
-   Triple.getOS() == llvm::Triple::NetBSD ||
+} else if (Triple.isOSFreeBSD() ||
+   Triple.isOSOpenBSD() ||
+   Triple.isOSNetBSD() ||
Triple.getOS() == llvm::Triple::Darwin) {
   if (Triple.getArch() != llvm::Triple::x86_64) {
 D.Diag(diag::err_drv_clang_unsupported)
Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -2597,7 +2597,7 @@
   bool UseInitArrayDefault =
   getTriple().getArch() == llvm::Triple::aarch64 ||
   getTriple().getArch() == llvm::Triple::aarch64_be ||
-  (getTriple().getOS() == llvm::Triple::FreeBSD &&
+  (getTriple().isOSFreeBSD() &&
getTriple().getOSMajorVersion() >= 12) ||
   (getTriple().getOS() == llvm::Triple::Linux &&
((!GCCInstallation.isValid() || !V.isOlderThan(4, 7, 0)) ||
Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -603,19 +603,19 @@
   if (TC.getTriple().getOS() != llvm::Triple::RTEMS &&
   !TC.getTriple().isAndroid()) {
 CmdArgs.push_back("-lpthread");
-if (TC.getTriple().getOS() != llvm::Triple::OpenBSD)
+if (TC.getTriple().isOSOpenBSD())
   CmdArgs.push_back("-lrt");
   }
   CmdArgs.push_back("-lm");
   // There's no libdl on all OSes.
-  if (TC.getTriple().getOS() != llvm::Triple::FreeBSD &&
-  TC.getTriple().getOS() != llvm::Triple::NetBSD &&
-  TC.getTriple().getOS() != llvm::Triple::OpenBSD &&
-  TC.getTriple().getOS() != llvm::Triple::RTEMS)
+  if (!TC.getTriple().isOSFreeBSD() &&
+  !TC.getTriple().isOSNetBSD() &&
+  !TC.getTriple().isOSOpenBSD() &&
+   TC.getTriple().getOS() != llvm::Triple::RTEMS)
 CmdArgs.push_back("-ldl");
   // Required for backtrace on some OSes
-  if (TC.getTriple().getOS() == llvm::Triple::NetBSD ||
-  TC.getTriple().getOS() == llvm::Triple::FreeBSD)
+  if (TC.getTriple().isOSFreeBSD() ||
+  TC.getTriple().isOSNetBSD())
 CmdArgs.push_back("-lexecinfo");
 }
 
@@ -790,13 +790,13 @@
 void tools::linkXRayRuntimeDeps(const ToolChain &TC, ArgStringList &CmdArgs) {
   CmdArgs.push_back("--no-as-needed");
   CmdArgs.push_back("-lpthread");
-  if (TC.getTriple().getOS() != llvm::Triple::OpenBSD)
+  if (!TC.getTriple().isOSOpenBSD())
 CmdArgs.push_back("-lrt");
   CmdArgs.push_back("-lm");
 
-  if (TC.getTriple().getOS() != llvm::Triple::FreeBSD &&
-  TC.getTriple().getOS() != llvm::Triple::NetBSD &&
-  TC.getTriple().getOS() != llvm::Triple::OpenBSD)
+  if (!TC.getTriple().isOSFreeBSD() &&
+  !TC.getTriple().isOSNetBSD() &&
+  !TC.getTriple().isOSOpenBSD())
 CmdArgs.push_back("-ldl");
 }
 
@@ -933,

[PATCH] D55916: [clang] Replace getOS() == llvm::Triple::*BSD with isOS*BSD() [NFCI]

2018-12-20 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179021.

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

https://reviews.llvm.org/D55916

Files:
  lib/Basic/Targets/AArch64.cpp
  lib/Basic/Targets/ARM.cpp
  lib/Basic/Targets/Mips.h
  lib/Basic/Targets/PPC.cpp
  lib/Basic/Targets/PPC.h
  lib/Basic/Targets/Sparc.h
  lib/Driver/ToolChains/Arch/Mips.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/CommonArgs.cpp
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/XRayArgs.cpp
  lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp

Index: lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
===
--- lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
+++ lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
@@ -29,10 +29,10 @@
   const llvm::Triple &T = Ctx.getTargetInfo().getTriple();
   return T.getVendor() == llvm::Triple::Apple ||
  T.getOS() == llvm::Triple::CloudABI ||
- T.getOS() == llvm::Triple::FreeBSD ||
- T.getOS() == llvm::Triple::NetBSD ||
- T.getOS() == llvm::Triple::OpenBSD ||
- T.getOS() == llvm::Triple::DragonFly;
+ T.isOSFreeBSD() ||
+ T.isOSNetBSD() ||
+ T.isOSOpenBSD() ||
+ T.isOSDragonFly();
 }
 
 namespace {
Index: lib/Driver/XRayArgs.cpp
===
--- lib/Driver/XRayArgs.cpp
+++ lib/Driver/XRayArgs.cpp
@@ -50,9 +50,9 @@
 D.Diag(diag::err_drv_clang_unsupported)
 << (std::string(XRayInstrumentOption) + " on " + Triple.str());
   }
-} else if (Triple.getOS() == llvm::Triple::FreeBSD ||
-   Triple.getOS() == llvm::Triple::OpenBSD ||
-   Triple.getOS() == llvm::Triple::NetBSD ||
+} else if (Triple.isOSFreeBSD() ||
+   Triple.isOSOpenBSD() ||
+   Triple.isOSNetBSD() ||
Triple.getOS() == llvm::Triple::Darwin) {
   if (Triple.getArch() != llvm::Triple::x86_64) {
 D.Diag(diag::err_drv_clang_unsupported)
Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -2597,7 +2597,7 @@
   bool UseInitArrayDefault =
   getTriple().getArch() == llvm::Triple::aarch64 ||
   getTriple().getArch() == llvm::Triple::aarch64_be ||
-  (getTriple().getOS() == llvm::Triple::FreeBSD &&
+  (getTriple().isOSFreeBSD() &&
getTriple().getOSMajorVersion() >= 12) ||
   (getTriple().getOS() == llvm::Triple::Linux &&
((!GCCInstallation.isValid() || !V.isOlderThan(4, 7, 0)) ||
Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -603,19 +603,19 @@
   if (TC.getTriple().getOS() != llvm::Triple::RTEMS &&
   !TC.getTriple().isAndroid()) {
 CmdArgs.push_back("-lpthread");
-if (TC.getTriple().getOS() != llvm::Triple::OpenBSD)
+if (TC.getTriple().isOSOpenBSD())
   CmdArgs.push_back("-lrt");
   }
   CmdArgs.push_back("-lm");
   // There's no libdl on all OSes.
-  if (TC.getTriple().getOS() != llvm::Triple::FreeBSD &&
-  TC.getTriple().getOS() != llvm::Triple::NetBSD &&
-  TC.getTriple().getOS() != llvm::Triple::OpenBSD &&
-  TC.getTriple().getOS() != llvm::Triple::RTEMS)
+  if (!TC.getTriple().isOSFreeBSD() &&
+  !TC.getTriple().isOSNetBSD() &&
+  !TC.getTriple().isOSOpenBSD() &&
+   TC.getTriple().getOS() != llvm::Triple::RTEMS)
 CmdArgs.push_back("-ldl");
   // Required for backtrace on some OSes
-  if (TC.getTriple().getOS() == llvm::Triple::NetBSD ||
-  TC.getTriple().getOS() == llvm::Triple::FreeBSD)
+  if (TC.getTriple().isOSFreeBSD() ||
+  TC.getTriple().isOSNetBSD())
 CmdArgs.push_back("-lexecinfo");
 }
 
@@ -790,13 +790,13 @@
 void tools::linkXRayRuntimeDeps(const ToolChain &TC, ArgStringList &CmdArgs) {
   CmdArgs.push_back("--no-as-needed");
   CmdArgs.push_back("-lpthread");
-  if (TC.getTriple().getOS() != llvm::Triple::OpenBSD)
+  if (!TC.getTriple().isOSOpenBSD())
 CmdArgs.push_back("-lrt");
   CmdArgs.push_back("-lm");
 
-  if (TC.getTriple().getOS() != llvm::Triple::FreeBSD &&
-  TC.getTriple().getOS() != llvm::Triple::NetBSD &&
-  TC.getTriple().getOS() != llvm::Triple::OpenBSD)
+  if (!TC.getTriple().isOSFreeBSD() &&
+  !TC.getTriple().isOSNetBSD() &&
+  !TC.getTriple().isOSOpenBSD())
 CmdArgs.push_back("-ldl");
 }
 
@@ -933,7 +933,7 @@
   }
 
   // OpenBSD-specific defaults for PIE
-  if (Triple.getOS() == llvm::Triple::OpenBSD) {
+  if (Triple.isOSOpenBSD()) {
 switch (ToolChain.getArch()) {
 case llvm::Triple::arm:
 case llvm::Triple::aarch64:
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolCha

[PATCH] D55916: [clang] Replace getOS() == llvm::Triple::*BSD with isOS*BSD() [NFCI]

2018-12-20 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179031.
mgorny marked 2 inline comments as done.

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

https://reviews.llvm.org/D55916

Files:
  lib/Basic/Targets/AArch64.cpp
  lib/Basic/Targets/ARM.cpp
  lib/Basic/Targets/Mips.h
  lib/Basic/Targets/PPC.cpp
  lib/Basic/Targets/PPC.h
  lib/Basic/Targets/Sparc.h
  lib/Driver/ToolChains/Arch/Mips.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/CommonArgs.cpp
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/XRayArgs.cpp
  lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp

Index: lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
===
--- lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
+++ lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
@@ -29,10 +29,10 @@
   const llvm::Triple &T = Ctx.getTargetInfo().getTriple();
   return T.getVendor() == llvm::Triple::Apple ||
  T.getOS() == llvm::Triple::CloudABI ||
- T.getOS() == llvm::Triple::FreeBSD ||
- T.getOS() == llvm::Triple::NetBSD ||
- T.getOS() == llvm::Triple::OpenBSD ||
- T.getOS() == llvm::Triple::DragonFly;
+ T.isOSFreeBSD() ||
+ T.isOSNetBSD() ||
+ T.isOSOpenBSD() ||
+ T.isOSDragonFly();
 }
 
 namespace {
Index: lib/Driver/XRayArgs.cpp
===
--- lib/Driver/XRayArgs.cpp
+++ lib/Driver/XRayArgs.cpp
@@ -50,9 +50,9 @@
 D.Diag(diag::err_drv_clang_unsupported)
 << (std::string(XRayInstrumentOption) + " on " + Triple.str());
   }
-} else if (Triple.getOS() == llvm::Triple::FreeBSD ||
-   Triple.getOS() == llvm::Triple::OpenBSD ||
-   Triple.getOS() == llvm::Triple::NetBSD ||
+} else if (Triple.isOSFreeBSD() ||
+   Triple.isOSOpenBSD() ||
+   Triple.isOSNetBSD() ||
Triple.getOS() == llvm::Triple::Darwin) {
   if (Triple.getArch() != llvm::Triple::x86_64) {
 D.Diag(diag::err_drv_clang_unsupported)
Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -2597,7 +2597,7 @@
   bool UseInitArrayDefault =
   getTriple().getArch() == llvm::Triple::aarch64 ||
   getTriple().getArch() == llvm::Triple::aarch64_be ||
-  (getTriple().getOS() == llvm::Triple::FreeBSD &&
+  (getTriple().isOSFreeBSD() &&
getTriple().getOSMajorVersion() >= 12) ||
   (getTriple().getOS() == llvm::Triple::Linux &&
((!GCCInstallation.isValid() || !V.isOlderThan(4, 7, 0)) ||
Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -603,19 +603,19 @@
   if (TC.getTriple().getOS() != llvm::Triple::RTEMS &&
   !TC.getTriple().isAndroid()) {
 CmdArgs.push_back("-lpthread");
-if (TC.getTriple().getOS() != llvm::Triple::OpenBSD)
+if (TC.getTriple().isOSOpenBSD())
   CmdArgs.push_back("-lrt");
   }
   CmdArgs.push_back("-lm");
   // There's no libdl on all OSes.
-  if (TC.getTriple().getOS() != llvm::Triple::FreeBSD &&
-  TC.getTriple().getOS() != llvm::Triple::NetBSD &&
-  TC.getTriple().getOS() != llvm::Triple::OpenBSD &&
-  TC.getTriple().getOS() != llvm::Triple::RTEMS)
+  if (!TC.getTriple().isOSFreeBSD() &&
+  !TC.getTriple().isOSNetBSD() &&
+  !TC.getTriple().isOSOpenBSD() &&
+   TC.getTriple().getOS() != llvm::Triple::RTEMS)
 CmdArgs.push_back("-ldl");
   // Required for backtrace on some OSes
-  if (TC.getTriple().getOS() == llvm::Triple::NetBSD ||
-  TC.getTriple().getOS() == llvm::Triple::FreeBSD)
+  if (TC.getTriple().isOSFreeBSD() ||
+  TC.getTriple().isOSNetBSD())
 CmdArgs.push_back("-lexecinfo");
 }
 
@@ -790,13 +790,13 @@
 void tools::linkXRayRuntimeDeps(const ToolChain &TC, ArgStringList &CmdArgs) {
   CmdArgs.push_back("--no-as-needed");
   CmdArgs.push_back("-lpthread");
-  if (TC.getTriple().getOS() != llvm::Triple::OpenBSD)
+  if (!TC.getTriple().isOSOpenBSD())
 CmdArgs.push_back("-lrt");
   CmdArgs.push_back("-lm");
 
-  if (TC.getTriple().getOS() != llvm::Triple::FreeBSD &&
-  TC.getTriple().getOS() != llvm::Triple::NetBSD &&
-  TC.getTriple().getOS() != llvm::Triple::OpenBSD)
+  if (!TC.getTriple().isOSFreeBSD() &&
+  !TC.getTriple().isOSNetBSD() &&
+  !TC.getTriple().isOSOpenBSD())
 CmdArgs.push_back("-ldl");
 }
 
@@ -933,7 +933,7 @@
   }
 
   // OpenBSD-specific defaults for PIE
-  if (Triple.getOS() == llvm::Triple::OpenBSD) {
+  if (Triple.isOSOpenBSD()) {
 switch (ToolChain.getArch()) {
 case llvm::Triple::arm:
 case llvm::Triple::aarch64:
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/To

[PATCH] D55916: [clang] Replace getOS() == llvm::Triple::*BSD with isOS*BSD() [NFCI]

2018-12-20 Thread Michał Górny via Phabricator via cfe-commits
mgorny added inline comments.



Comment at: lib/Basic/Targets/ARM.cpp:285
 default:
-  if (Triple.getOS() == llvm::Triple::NetBSD)
+  if (Triple.isOSNetBSD())
 setABI("apcs-gnu");

krytarowski wrote:
> Actually we could use IsNetBSD and IsOpenBSD here.
Good catch. Thanks!


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

https://reviews.llvm.org/D55916



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55916: [clang] Replace getOS() == llvm::Triple::*BSD with isOS*BSD() [NFCI]

2018-12-20 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349752: Replace getOS() == llvm::Triple::*BSD with 
isOS*BSD() [NFCI] (authored by mgorny, committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D55916

Files:
  lib/Basic/Targets/AArch64.cpp
  lib/Basic/Targets/ARM.cpp
  lib/Basic/Targets/Mips.h
  lib/Basic/Targets/PPC.cpp
  lib/Basic/Targets/PPC.h
  lib/Basic/Targets/Sparc.h
  lib/Driver/ToolChains/Arch/Mips.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/CommonArgs.cpp
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/XRayArgs.cpp
  lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp

Index: lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
===
--- lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
+++ lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
@@ -29,10 +29,10 @@
   const llvm::Triple &T = Ctx.getTargetInfo().getTriple();
   return T.getVendor() == llvm::Triple::Apple ||
  T.getOS() == llvm::Triple::CloudABI ||
- T.getOS() == llvm::Triple::FreeBSD ||
- T.getOS() == llvm::Triple::NetBSD ||
- T.getOS() == llvm::Triple::OpenBSD ||
- T.getOS() == llvm::Triple::DragonFly;
+ T.isOSFreeBSD() ||
+ T.isOSNetBSD() ||
+ T.isOSOpenBSD() ||
+ T.isOSDragonFly();
 }
 
 namespace {
Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -2597,7 +2597,7 @@
   bool UseInitArrayDefault =
   getTriple().getArch() == llvm::Triple::aarch64 ||
   getTriple().getArch() == llvm::Triple::aarch64_be ||
-  (getTriple().getOS() == llvm::Triple::FreeBSD &&
+  (getTriple().isOSFreeBSD() &&
getTriple().getOSMajorVersion() >= 12) ||
   (getTriple().getOS() == llvm::Triple::Linux &&
((!GCCInstallation.isValid() || !V.isOlderThan(4, 7, 0)) ||
Index: lib/Driver/ToolChains/Arch/Mips.cpp
===
--- lib/Driver/ToolChains/Arch/Mips.cpp
+++ lib/Driver/ToolChains/Arch/Mips.cpp
@@ -47,12 +47,12 @@
   }
 
   // MIPS3 is the default for mips64*-unknown-openbsd.
-  if (Triple.getOS() == llvm::Triple::OpenBSD)
+  if (Triple.isOSOpenBSD())
 DefMips64CPU = "mips3";
 
   // MIPS2 is the default for mips(el)?-unknown-freebsd.
   // MIPS3 is the default for mips64(el)?-unknown-freebsd.
-  if (Triple.getOS() == llvm::Triple::FreeBSD) {
+  if (Triple.isOSFreeBSD()) {
 DefMips32CPU = "mips2";
 DefMips64CPU = "mips3";
   }
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -526,7 +526,7 @@
 break;
   }
 
-  if (Triple.getOS() == llvm::Triple::NetBSD) {
+  if (Triple.isOSNetBSD()) {
 return !areOptimizationsEnabled(Args);
   }
 
@@ -2848,8 +2848,8 @@
 } else {
   bool IsARM = T.isARM() || T.isThumb() || T.isAArch64();
   CmdArgs.push_back("-fwchar-type=int");
-  if (IsARM && !(T.isOSWindows() || T.getOS() == llvm::Triple::NetBSD ||
- T.getOS() == llvm::Triple::OpenBSD))
+  if (IsARM && !(T.isOSWindows() || T.isOSNetBSD() ||
+ T.isOSOpenBSD()))
 CmdArgs.push_back("-fno-signed-wchar");
   else
 CmdArgs.push_back("-fsigned-wchar");
@@ -5274,8 +5274,8 @@
(TC.getTriple().isOSBinFormatELF() ||
 TC.getTriple().isOSBinFormatCOFF()) &&
   !TC.getTriple().isPS4() &&
-   TC.useIntegratedAs() &&
-   RawTriple.getOS() != llvm::Triple::NetBSD))
+  !TC.getTriple().isOSNetBSD() &&
+   TC.useIntegratedAs()))
 CmdArgs.push_back("-faddrsig");
 
   // Finally add the compile command to the compilation.
Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -603,19 +603,19 @@
   if (TC.getTriple().getOS() != llvm::Triple::RTEMS &&
   !TC.getTriple().isAndroid()) {
 CmdArgs.push_back("-lpthread");
-if (TC.getTriple().getOS() != llvm::Triple::OpenBSD)
+if (TC.getTriple().isOSOpenBSD())
   CmdArgs.push_back("-lrt");
   }
   CmdArgs.push_back("-lm");
   // There's no libdl on all OSes.
-  if (TC.getTriple().getOS() != llvm::Triple::FreeBSD &&
-  TC.getTriple().getOS() != llvm::Triple::NetBSD &&
-  TC.getTriple().getOS() != llvm::Triple::OpenBSD &&
-  TC.getTriple().getOS() != llvm::Triple::RTEMS)
+  if (!TC.getTriple().isOSFreeBSD() &&
+  !TC.getTriple().isOSNetBSD() &&
+  !TC.getTriple().isOSOpenBSD() &&
+   TC.getTriple().getOS() 

[PATCH] D55891: [compiler-rt] [xray] [tests] Detect and handle missing LLVMTestingSupport gracefully

2018-12-21 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349899: [xray] [tests] Detect and handle missing 
LLVMTestingSupport gracefully (authored by mgorny, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D55891?vs=178896&id=179275#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55891

Files:
  compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake
  compiler-rt/trunk/lib/xray/tests/CMakeLists.txt
  compiler-rt/trunk/lib/xray/tests/unit/CMakeLists.txt


Index: compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake
===
--- compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake
+++ compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake
@@ -239,7 +239,7 @@
 # Detect if we have the LLVMXRay and TestingSupport library installed and
 # available from llvm-config.
 execute_process(
-  COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "xray" "testingsupport"
+  COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "xray"
   RESULT_VARIABLE HAD_ERROR
   OUTPUT_VARIABLE CONFIG_OUTPUT)
 if (HAD_ERROR)
@@ -254,6 +254,26 @@
   set(COMPILER_RT_HAS_LLVMXRAY TRUE)
 endif()
 
+set(COMPILER_RT_HAS_LLVMTESTINGSUPPORT FALSE)
+execute_process(
+  COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "testingsupport"
+  RESULT_VARIABLE HAD_ERROR
+  OUTPUT_VARIABLE CONFIG_OUTPUT)
+if (HAD_ERROR)
+  message(WARNING "llvm-config finding testingsupport failed with status 
${HAD_ERROR}")
+else()
+  string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" CONFIG_OUTPUT 
${CONFIG_OUTPUT})
+  list(GET CONFIG_OUTPUT 0 LDFLAGS)
+  list(GET CONFIG_OUTPUT 1 LIBLIST)
+  if (LIBLIST STREQUAL "")
+message(WARNING "testingsupport library not installed, some tests will 
be skipped")
+  else()
+set(LLVM_TESTINGSUPPORT_LDFLAGS ${LDFLAGS} CACHE STRING "Linker flags 
for LLVMTestingSupport library")
+set(LLVM_TESTINGSUPPORT_LIBLIST ${LIBLIST} CACHE STRING "Library list 
for LLVMTestingSupport")
+set(COMPILER_RT_HAS_LLVMTESTINGSUPPORT TRUE)
+  endif()
+endif()
+
 # Make use of LLVM CMake modules.
 # --cmakedir is supported since llvm r291218 (4.0 release)
 execute_process(
Index: compiler-rt/trunk/lib/xray/tests/unit/CMakeLists.txt
===
--- compiler-rt/trunk/lib/xray/tests/unit/CMakeLists.txt
+++ compiler-rt/trunk/lib/xray/tests/unit/CMakeLists.txt
@@ -1,10 +1,16 @@
-add_xray_unittest(XRayTest SOURCES
+set(TEST_SOURCES
   allocator_test.cc
   buffer_queue_test.cc
-  fdr_controller_test.cc
-  fdr_log_writer_test.cc
   function_call_trie_test.cc
   profile_collector_test.cc
   segmented_array_test.cc
   test_helpers.cc
   xray_unit_test_main.cc)
+
+if (NOT COMPILER_RT_STANDALONE_BUILD OR COMPILER_RT_HAS_LLVMTESTINGSUPPORT)
+  list(APPEND TEST_SOURCES
+fdr_controller_test.cc
+fdr_log_writer_test.cc)
+endif()
+
+add_xray_unittest(XRayTest SOURCES ${TEST_SOURCES})
Index: compiler-rt/trunk/lib/xray/tests/CMakeLists.txt
===
--- compiler-rt/trunk/lib/xray/tests/CMakeLists.txt
+++ compiler-rt/trunk/lib/xray/tests/CMakeLists.txt
@@ -60,6 +60,10 @@
   if (COMPILER_RT_STANDALONE_BUILD)
 append_list_if(COMPILER_RT_HAS_LLVMXRAY ${LLVM_XRAY_LDFLAGS} 
XRAY_UNITTEST_LINK_FLAGS)
 append_list_if(COMPILER_RT_HAS_LLVMXRAY ${LLVM_XRAY_LIBLIST} 
XRAY_UNITTEST_LINK_FLAGS)
+append_list_if(COMPILER_RT_HAS_LLVMTESTINGSUPPORT
+  ${LLVM_TESTINGSUPPORT_LDFLAGS} XRAY_UNITTEST_LINK_FLAGS)
+append_list_if(COMPILER_RT_HAS_LLVMTESTINGSUPPORT
+  ${LLVM_TESTINGSUPPORT_LIBLIST} XRAY_UNITTEST_LINK_FLAGS)
   else()
 # We add the library directories one at a time in our CFLAGS.
 foreach (DIR ${LLVM_LIBRARY_DIR})


Index: compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake
===
--- compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake
+++ compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake
@@ -239,7 +239,7 @@
 # Detect if we have the LLVMXRay and TestingSupport library installed and
 # available from llvm-config.
 execute_process(
-  COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "xray" "testingsupport"
+  COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "xray"
   RESULT_VARIABLE HAD_ERROR
   OUTPUT_VARIABLE CONFIG_OUTPUT)
 if (HAD_ERROR)
@@ -254,6 +254,26 @@
   set(COMPILER_RT_HAS_LLVMXRAY TRUE)
 endif()
 
+set(COMPILER_RT_HAS_LLVMTESTINGSUPPORT FALSE)
+execute_process(
+  COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "testingsupport"
+  RESULT_VARIABLE HAD_ERROR
+  OUTPUT_VARIABLE CONFIG_OUTPUT)
+if (HAD_ERROR)
+  message(WARNING "llvm-config 

[PATCH] D55916: [clang] Replace getOS() == llvm::Triple::*BSD with isOS*BSD() [NFCI]

2018-12-21 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

No problem. I'm sorry about my initial mistake. Apparently it slipped me even 
though I've double checked it originally.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55916



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56000: [compiler-rt] [xray] Disable alignas() for thread_local objects on NetBSD

2018-12-21 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, dberris, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits.

Disable enforcing alignas() for structs that are used as thread_local
data on NetBSD.  The NetBSD ld.so implementation is buggy and does
not enforce correct alignment; however, clang seems to take it for
granted and generates instructions that segv on wrongly aligned objects.
Therefore, disable those alignas() statements on NetBSD until we can
establish a better fix.

Apparently, std::aligned_storage<> does not have any real effect
at the moment, so we can leave it as-is.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56000

Files:
  lib/xray/xray_basic_logging.cc
  lib/xray/xray_fdr_logging.cc


Index: lib/xray/xray_fdr_logging.cc
===
--- lib/xray/xray_fdr_logging.cc
+++ lib/xray/xray_fdr_logging.cc
@@ -51,7 +51,12 @@
 // call so that it can be initialized on first use instead of as a global. We
 // force the alignment to 64-bytes for x86 cache line alignment, as this
 // structure is used in the hot path of implementation.
-struct alignas(64) ThreadLocalData {
+struct
+/* TLD is not aligned properly on NetBSD, resulting in segfault */
+#if !SANITIZER_NETBSD
+alignas(64)
+#endif
+ThreadLocalData {
   BufferQueue::Buffer Buffer{};
   BufferQueue *BQ = nullptr;
 
@@ -124,8 +129,10 @@
 // critical section, calling a function that might be XRay instrumented (and
 // thus in turn calling into malloc by virtue of registration of the
 // thread_local's destructor).
+#if !SANITIZER_NETBSD
 static_assert(alignof(ThreadLocalData) >= 64,
   "ThreadLocalData must be cache line aligned.");
+#endif
 static ThreadLocalData &getThreadLocalData() {
   thread_local typename std::aligned_storage<
   sizeof(ThreadLocalData), alignof(ThreadLocalData)>::type TLDStorage{};
Index: lib/xray/xray_basic_logging.cc
===
--- lib/xray/xray_basic_logging.cc
+++ lib/xray/xray_basic_logging.cc
@@ -55,7 +55,12 @@
 
 static_assert(sizeof(StackEntry) == 16, "Wrong size for StackEntry");
 
-struct alignas(64) ThreadLocalData {
+struct
+/* TLD is not aligned properly on NetBSD, resulting in segfault */
+#if !SANITIZER_NETBSD
+alignas(64)
+#endif
+ThreadLocalData {
   void *InMemoryBuffer = nullptr;
   size_t BufferSize = 0;
   size_t BufferOffset = 0;


Index: lib/xray/xray_fdr_logging.cc
===
--- lib/xray/xray_fdr_logging.cc
+++ lib/xray/xray_fdr_logging.cc
@@ -51,7 +51,12 @@
 // call so that it can be initialized on first use instead of as a global. We
 // force the alignment to 64-bytes for x86 cache line alignment, as this
 // structure is used in the hot path of implementation.
-struct alignas(64) ThreadLocalData {
+struct
+/* TLD is not aligned properly on NetBSD, resulting in segfault */
+#if !SANITIZER_NETBSD
+alignas(64)
+#endif
+ThreadLocalData {
   BufferQueue::Buffer Buffer{};
   BufferQueue *BQ = nullptr;
 
@@ -124,8 +129,10 @@
 // critical section, calling a function that might be XRay instrumented (and
 // thus in turn calling into malloc by virtue of registration of the
 // thread_local's destructor).
+#if !SANITIZER_NETBSD
 static_assert(alignof(ThreadLocalData) >= 64,
   "ThreadLocalData must be cache line aligned.");
+#endif
 static ThreadLocalData &getThreadLocalData() {
   thread_local typename std::aligned_storage<
   sizeof(ThreadLocalData), alignof(ThreadLocalData)>::type TLDStorage{};
Index: lib/xray/xray_basic_logging.cc
===
--- lib/xray/xray_basic_logging.cc
+++ lib/xray/xray_basic_logging.cc
@@ -55,7 +55,12 @@
 
 static_assert(sizeof(StackEntry) == 16, "Wrong size for StackEntry");
 
-struct alignas(64) ThreadLocalData {
+struct
+/* TLD is not aligned properly on NetBSD, resulting in segfault */
+#if !SANITIZER_NETBSD
+alignas(64)
+#endif
+ThreadLocalData {
   void *InMemoryBuffer = nullptr;
   size_t BufferSize = 0;
   size_t BufferOffset = 0;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56000: [compiler-rt] [xray] Disable alignas() for thread_local objects on NetBSD

2018-12-21 Thread Michał Górny via Phabricator via cfe-commits
mgorny marked an inline comment as done.
mgorny added inline comments.



Comment at: lib/xray/xray_basic_logging.cc:58
 
-struct alignas(64) ThreadLocalData {
+struct
+/* TLD is not aligned properly on NetBSD, resulting in segfault */

krytarowski wrote:
> Can we introduce a macro like:
> 
> ```
> #if SANITIZER_NETBSD
> #define XRAY_TLS_ALIGNAS64 /* Nor supported */
> #else
> #define XRAY_TLS_ALIGNED_SUPPORTED
> #define XRAY_TLS_ALIGNAS64 alignas(64)
> #endif
> ```
> 
> And later:
> 
> ```
> struct XRAY_TLS_ALIGNAS64 ThreadLocalData {
> ```
> 
> and
> 
> ```
> #ifdef XRAY_TLS_ALIGNED_SUPPORTED
> static_assert(alignof(ThreadLocalData) >= 64,
>   "ThreadLocalData must be cache line aligned.");
> #endif
> ```
Maybe. Though i suppose it'd make more sense to make `64` an argument to the 
macro.


Repository:
  rCRT Compiler Runtime

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

https://reviews.llvm.org/D56000



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56000: [compiler-rt] [xray] Disable alignas() for thread_local objects on NetBSD

2018-12-21 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179297.

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

https://reviews.llvm.org/D56000

Files:
  lib/xray/xray_basic_logging.cc
  lib/xray/xray_defs.h
  lib/xray/xray_fdr_logging.cc


Index: lib/xray/xray_fdr_logging.cc
===
--- lib/xray/xray_fdr_logging.cc
+++ lib/xray/xray_fdr_logging.cc
@@ -51,7 +51,7 @@
 // call so that it can be initialized on first use instead of as a global. We
 // force the alignment to 64-bytes for x86 cache line alignment, as this
 // structure is used in the hot path of implementation.
-struct alignas(64) ThreadLocalData {
+struct XRAY_TLS_ALIGNAS(64) ThreadLocalData {
   BufferQueue::Buffer Buffer{};
   BufferQueue *BQ = nullptr;
 
@@ -124,8 +124,10 @@
 // critical section, calling a function that might be XRay instrumented (and
 // thus in turn calling into malloc by virtue of registration of the
 // thread_local's destructor).
+#if XRAY_HAS_TLS_ALIGNAS
 static_assert(alignof(ThreadLocalData) >= 64,
   "ThreadLocalData must be cache line aligned.");
+#endif
 static ThreadLocalData &getThreadLocalData() {
   thread_local typename std::aligned_storage<
   sizeof(ThreadLocalData), alignof(ThreadLocalData)>::type TLDStorage{};
Index: lib/xray/xray_defs.h
===
--- lib/xray/xray_defs.h
+++ lib/xray/xray_defs.h
@@ -19,4 +19,14 @@
 #define XRAY_NEVER_INSTRUMENT
 #endif
 
+#if !SANITIZER_NETBSD
+#define XRAY_TLS_ALIGNAS(x) alignas(x)
+#define XRAY_HAS_TLS_ALIGNAS 1
+#else
+// NetBSD: thread_local is not aligned properly, and the code relying
+// on it segfaults
+#define XRAY_TLS_ALIGNAS(x)
+#define XRAY_HAS_TLS_ALIGNAS 0
+#endif
+
 #endif  // XRAY_XRAY_DEFS_H
Index: lib/xray/xray_basic_logging.cc
===
--- lib/xray/xray_basic_logging.cc
+++ lib/xray/xray_basic_logging.cc
@@ -55,7 +55,7 @@
 
 static_assert(sizeof(StackEntry) == 16, "Wrong size for StackEntry");
 
-struct alignas(64) ThreadLocalData {
+struct XRAY_TLS_ALIGNAS(64) ThreadLocalData {
   void *InMemoryBuffer = nullptr;
   size_t BufferSize = 0;
   size_t BufferOffset = 0;


Index: lib/xray/xray_fdr_logging.cc
===
--- lib/xray/xray_fdr_logging.cc
+++ lib/xray/xray_fdr_logging.cc
@@ -51,7 +51,7 @@
 // call so that it can be initialized on first use instead of as a global. We
 // force the alignment to 64-bytes for x86 cache line alignment, as this
 // structure is used in the hot path of implementation.
-struct alignas(64) ThreadLocalData {
+struct XRAY_TLS_ALIGNAS(64) ThreadLocalData {
   BufferQueue::Buffer Buffer{};
   BufferQueue *BQ = nullptr;
 
@@ -124,8 +124,10 @@
 // critical section, calling a function that might be XRay instrumented (and
 // thus in turn calling into malloc by virtue of registration of the
 // thread_local's destructor).
+#if XRAY_HAS_TLS_ALIGNAS
 static_assert(alignof(ThreadLocalData) >= 64,
   "ThreadLocalData must be cache line aligned.");
+#endif
 static ThreadLocalData &getThreadLocalData() {
   thread_local typename std::aligned_storage<
   sizeof(ThreadLocalData), alignof(ThreadLocalData)>::type TLDStorage{};
Index: lib/xray/xray_defs.h
===
--- lib/xray/xray_defs.h
+++ lib/xray/xray_defs.h
@@ -19,4 +19,14 @@
 #define XRAY_NEVER_INSTRUMENT
 #endif
 
+#if !SANITIZER_NETBSD
+#define XRAY_TLS_ALIGNAS(x) alignas(x)
+#define XRAY_HAS_TLS_ALIGNAS 1
+#else
+// NetBSD: thread_local is not aligned properly, and the code relying
+// on it segfaults
+#define XRAY_TLS_ALIGNAS(x)
+#define XRAY_HAS_TLS_ALIGNAS 0
+#endif
+
 #endif  // XRAY_XRAY_DEFS_H
Index: lib/xray/xray_basic_logging.cc
===
--- lib/xray/xray_basic_logging.cc
+++ lib/xray/xray_basic_logging.cc
@@ -55,7 +55,7 @@
 
 static_assert(sizeof(StackEntry) == 16, "Wrong size for StackEntry");
 
-struct alignas(64) ThreadLocalData {
+struct XRAY_TLS_ALIGNAS(64) ThreadLocalData {
   void *InMemoryBuffer = nullptr;
   size_t BufferSize = 0;
   size_t BufferOffset = 0;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56000: [compiler-rt] [xray] Disable alignas() for thread_local objects on NetBSD

2018-12-21 Thread Michał Górny via Phabricator via cfe-commits
mgorny marked 3 inline comments as done.
mgorny added a comment.

Updated as requested.


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

https://reviews.llvm.org/D56000



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56024: [clang] [Distro] Support detecting Gentoo

2018-12-21 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: sylvestre.ledru, bruno, bkramer, phosek.

Add support for distinguishing plain Gentoo distribution, and a unit
test for it.  This is going to be used to introduce distro-specific
customizations in the driver code; most notably, it is going to be used
to disable -faddrsig.


Repository:
  rC Clang

https://reviews.llvm.org/D56024

Files:
  include/clang/Driver/Distro.h
  lib/Driver/Distro.cpp
  unittests/Driver/DistroTest.cpp


Index: unittests/Driver/DistroTest.cpp
===
--- unittests/Driver/DistroTest.cpp
+++ unittests/Driver/DistroTest.cpp
@@ -302,4 +302,28 @@
   ASSERT_FALSE(ArchLinux.IsDebian());
 }
 
+TEST(DistroTest, DetectGentoo) {
+  llvm::vfs::InMemoryFileSystem GentooFileSystem;
+  GentooFileSystem.addFile(
+  "/etc/gentoo-release", 0,
+  llvm::MemoryBuffer::getMemBuffer("Gentoo Base System release 2.6"));
+  GentooFileSystem.addFile(
+  "/etc/os-release", 0,
+  llvm::MemoryBuffer::getMemBuffer(
+  "NAME=Gentoo\n"
+  "ID=gentoo\n"
+  "PRETTY_NAME=\"Gentoo/Linux\"\n"
+  "ANSI_COLOR=\"1;32\"\n"
+  "HOME_URL=\"https://www.gentoo.org/\"\n";
+  "SUPPORT_URL=\"https://www.gentoo.org/support/\"\n";
+  "BUG_REPORT_URL=\"https://bugs.gentoo.org/\"\n";));
+
+  Distro Gentoo{GentooFileSystem};
+  ASSERT_EQ(Distro(Distro::Gentoo), Gentoo);
+  ASSERT_FALSE(Gentoo.IsUbuntu());
+  ASSERT_FALSE(Gentoo.IsRedhat());
+  ASSERT_FALSE(Gentoo.IsOpenSUSE());
+  ASSERT_FALSE(Gentoo.IsDebian());
+}
+
 } // end anonymous namespace
Index: lib/Driver/Distro.cpp
===
--- lib/Driver/Distro.cpp
+++ lib/Driver/Distro.cpp
@@ -138,6 +138,9 @@
   if (VFS.exists("/etc/arch-release"))
 return Distro::ArchLinux;
 
+  if (VFS.exists("/etc/gentoo-release"))
+return Distro::Gentoo;
+
   return Distro::UnknownDistro;
 }
 
Index: include/clang/Driver/Distro.h
===
--- include/clang/Driver/Distro.h
+++ include/clang/Driver/Distro.h
@@ -39,6 +39,7 @@
 RHEL6,
 RHEL7,
 Fedora,
+Gentoo,
 OpenSUSE,
 UbuntuHardy,
 UbuntuIntrepid,


Index: unittests/Driver/DistroTest.cpp
===
--- unittests/Driver/DistroTest.cpp
+++ unittests/Driver/DistroTest.cpp
@@ -302,4 +302,28 @@
   ASSERT_FALSE(ArchLinux.IsDebian());
 }
 
+TEST(DistroTest, DetectGentoo) {
+  llvm::vfs::InMemoryFileSystem GentooFileSystem;
+  GentooFileSystem.addFile(
+  "/etc/gentoo-release", 0,
+  llvm::MemoryBuffer::getMemBuffer("Gentoo Base System release 2.6"));
+  GentooFileSystem.addFile(
+  "/etc/os-release", 0,
+  llvm::MemoryBuffer::getMemBuffer(
+  "NAME=Gentoo\n"
+  "ID=gentoo\n"
+  "PRETTY_NAME=\"Gentoo/Linux\"\n"
+  "ANSI_COLOR=\"1;32\"\n"
+  "HOME_URL=\"https://www.gentoo.org/\"\n";
+  "SUPPORT_URL=\"https://www.gentoo.org/support/\"\n";
+  "BUG_REPORT_URL=\"https://bugs.gentoo.org/\"\n";));
+
+  Distro Gentoo{GentooFileSystem};
+  ASSERT_EQ(Distro(Distro::Gentoo), Gentoo);
+  ASSERT_FALSE(Gentoo.IsUbuntu());
+  ASSERT_FALSE(Gentoo.IsRedhat());
+  ASSERT_FALSE(Gentoo.IsOpenSUSE());
+  ASSERT_FALSE(Gentoo.IsDebian());
+}
+
 } // end anonymous namespace
Index: lib/Driver/Distro.cpp
===
--- lib/Driver/Distro.cpp
+++ lib/Driver/Distro.cpp
@@ -138,6 +138,9 @@
   if (VFS.exists("/etc/arch-release"))
 return Distro::ArchLinux;
 
+  if (VFS.exists("/etc/gentoo-release"))
+return Distro::Gentoo;
+
   return Distro::UnknownDistro;
 }
 
Index: include/clang/Driver/Distro.h
===
--- include/clang/Driver/Distro.h
+++ include/clang/Driver/Distro.h
@@ -39,6 +39,7 @@
 RHEL6,
 RHEL7,
 Fedora,
+Gentoo,
 OpenSUSE,
 UbuntuHardy,
 UbuntuIntrepid,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56024: [clang] [Distro] Support detecting Gentoo

2018-12-22 Thread Michał Górny via Phabricator via cfe-commits
mgorny marked an inline comment as done.
mgorny added inline comments.



Comment at: include/clang/Driver/Distro.h:118
   }
 
   bool IsUbuntu() const {

phosek wrote:
> Shall we also introduce the `IsGentoo()` predicate for convenience?
Hmm, I originally thought they only make sense when there's 1+ distro value for 
it. But I guess more distros are doing it for some reason.


Repository:
  rC Clang

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

https://reviews.llvm.org/D56024



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39588: Distro: initial support for alpine

2018-12-22 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.
Herald added a subscriber: llvm-commits.

I'm sorry for being late to the party but could you update 
`unittests/Driver/DistroTest.cpp` as well?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D39588



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56024: [clang] [Distro] Support detecting Gentoo

2018-12-22 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179413.
mgorny added a comment.

Now with `IsGentoo()` predicate.


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

https://reviews.llvm.org/D56024

Files:
  include/clang/Driver/Distro.h
  lib/Driver/Distro.cpp
  unittests/Driver/DistroTest.cpp

Index: unittests/Driver/DistroTest.cpp
===
--- unittests/Driver/DistroTest.cpp
+++ unittests/Driver/DistroTest.cpp
@@ -51,6 +51,7 @@
   ASSERT_FALSE(UbuntuTrusty.IsRedhat());
   ASSERT_FALSE(UbuntuTrusty.IsOpenSUSE());
   ASSERT_FALSE(UbuntuTrusty.IsDebian());
+  ASSERT_FALSE(UbuntuTrusty.IsGentoo());
 
   llvm::vfs::InMemoryFileSystem UbuntuYakketyFileSystem;
   UbuntuYakketyFileSystem.addFile("/etc/debian_version", 0,
@@ -80,6 +81,7 @@
   ASSERT_FALSE(UbuntuYakkety.IsRedhat());
   ASSERT_FALSE(UbuntuYakkety.IsOpenSUSE());
   ASSERT_FALSE(UbuntuYakkety.IsDebian());
+  ASSERT_FALSE(UbuntuYakkety.IsGentoo());
 }
 
 TEST(DistroTest, DetectRedhat) {
@@ -114,6 +116,7 @@
   ASSERT_TRUE(Fedora25.IsRedhat());
   ASSERT_FALSE(Fedora25.IsOpenSUSE());
   ASSERT_FALSE(Fedora25.IsDebian());
+  ASSERT_FALSE(Fedora25.IsGentoo());
 
   llvm::vfs::InMemoryFileSystem CentOS7FileSystem;
   CentOS7FileSystem.addFile("/etc/system-release-cpe", 0,
@@ -150,6 +153,7 @@
   ASSERT_TRUE(CentOS7.IsRedhat());
   ASSERT_FALSE(CentOS7.IsOpenSUSE());
   ASSERT_FALSE(CentOS7.IsDebian());
+  ASSERT_FALSE(CentOS7.IsGentoo());
 }
 
 TEST(DistroTest, DetectOpenSUSE) {
@@ -177,6 +181,7 @@
   ASSERT_FALSE(OpenSUSELeap421.IsRedhat());
   ASSERT_TRUE(OpenSUSELeap421.IsOpenSUSE());
   ASSERT_FALSE(OpenSUSELeap421.IsDebian());
+  ASSERT_FALSE(OpenSUSELeap421.IsGentoo());
 
   llvm::vfs::InMemoryFileSystem OpenSUSE132FileSystem;
   OpenSUSE132FileSystem.addFile("/etc/SuSE-release", 0,
@@ -202,6 +207,7 @@
   ASSERT_FALSE(OpenSUSE132.IsRedhat());
   ASSERT_TRUE(OpenSUSE132.IsOpenSUSE());
   ASSERT_FALSE(OpenSUSE132.IsDebian());
+  ASSERT_FALSE(OpenSUSE132.IsGentoo());
 
   llvm::vfs::InMemoryFileSystem SLES10FileSystem;
   SLES10FileSystem.addFile("/etc/SuSE-release", 0,
@@ -218,6 +224,7 @@
   ASSERT_FALSE(SLES10.IsRedhat());
   ASSERT_FALSE(SLES10.IsOpenSUSE());
   ASSERT_FALSE(SLES10.IsDebian());
+  ASSERT_FALSE(SLES10.IsGentoo());
 }
 
 TEST(DistroTest, DetectDebian) {
@@ -240,6 +247,7 @@
   ASSERT_FALSE(DebianJessie.IsRedhat());
   ASSERT_FALSE(DebianJessie.IsOpenSUSE());
   ASSERT_TRUE(DebianJessie.IsDebian());
+  ASSERT_FALSE(DebianJessie.IsGentoo());
 
   llvm::vfs::InMemoryFileSystem DebianStretchSidFileSystem;
   DebianStretchSidFileSystem.addFile("/etc/debian_version", 0,
@@ -258,6 +266,7 @@
   ASSERT_FALSE(DebianStretchSid.IsRedhat());
   ASSERT_FALSE(DebianStretchSid.IsOpenSUSE());
   ASSERT_TRUE(DebianStretchSid.IsDebian());
+  ASSERT_FALSE(DebianStretchSid.IsGentoo());
 }
 
 TEST(DistroTest, DetectExherbo) {
@@ -279,6 +288,7 @@
   ASSERT_FALSE(Exherbo.IsRedhat());
   ASSERT_FALSE(Exherbo.IsOpenSUSE());
   ASSERT_FALSE(Exherbo.IsDebian());
+  ASSERT_FALSE(Exherbo.IsGentoo());
 }
 
 TEST(DistroTest, DetectArchLinux) {
@@ -300,6 +310,32 @@
   ASSERT_FALSE(ArchLinux.IsRedhat());
   ASSERT_FALSE(ArchLinux.IsOpenSUSE());
   ASSERT_FALSE(ArchLinux.IsDebian());
+  ASSERT_FALSE(ArchLinux.IsGentoo());
+}
+
+TEST(DistroTest, DetectGentoo) {
+  llvm::vfs::InMemoryFileSystem GentooFileSystem;
+  GentooFileSystem.addFile(
+  "/etc/gentoo-release", 0,
+  llvm::MemoryBuffer::getMemBuffer("Gentoo Base System release 2.6"));
+  GentooFileSystem.addFile(
+  "/etc/os-release", 0,
+  llvm::MemoryBuffer::getMemBuffer(
+  "NAME=Gentoo\n"
+  "ID=gentoo\n"
+  "PRETTY_NAME=\"Gentoo/Linux\"\n"
+  "ANSI_COLOR=\"1;32\"\n"
+  "HOME_URL=\"https://www.gentoo.org/\"\n";
+  "SUPPORT_URL=\"https://www.gentoo.org/support/\"\n";
+  "BUG_REPORT_URL=\"https://bugs.gentoo.org/\"\n";));
+
+  Distro Gentoo{GentooFileSystem};
+  ASSERT_EQ(Distro(Distro::Gentoo), Gentoo);
+  ASSERT_FALSE(Gentoo.IsUbuntu());
+  ASSERT_FALSE(Gentoo.IsRedhat());
+  ASSERT_FALSE(Gentoo.IsOpenSUSE());
+  ASSERT_FALSE(Gentoo.IsDebian());
+  ASSERT_TRUE(Gentoo.IsGentoo());
 }
 
 } // end anonymous namespace
Index: lib/Driver/Distro.cpp
===
--- lib/Driver/Distro.cpp
+++ lib/Driver/Distro.cpp
@@ -138,6 +138,9 @@
   if (VFS.exists("/etc/arch-release"))
 return Distro::ArchLinux;
 
+  if (VFS.exists("/etc/gentoo-release"))
+return Distro::Gentoo;
+
   return Distro::UnknownDistro;
 }
 
Index: include/clang/Driver/Distro.h
===
--- include/clang/Driver/Distro.h
+++ include/clang/Driver/Distro.h
@@ -39,6 +39,7 @@
 RHEL6,
 RHEL7,
 Fedora,
+Gentoo,
 OpenSUSE,
 UbuntuHardy,
 UbuntuIntrepid,
@@ -123,6 +124,10 @@
 return DistroVal == AlpineLinux;
   }
 
+  bool IsGentoo() const {
+return DistroVal == Gentoo;
+  }
+
 

[PATCH] D56000: [compiler-rt] [xray] Disable alignas() for thread_local objects on NetBSD

2018-12-22 Thread Michał Górny via Phabricator via cfe-commits
mgorny marked an inline comment as done.
mgorny added inline comments.



Comment at: lib/xray/xray_defs.h:22
 
+#if !SANITIZER_NETBSD
+#define XRAY_TLS_ALIGNAS(x) alignas(x)

dberris wrote:
> krytarowski wrote:
> > I would switch the order, in order to remove unneeded negation.
> > 
> > ```
> > #if SANITIZER_NETBSD
> > ...
> > #else
> > ...
> > #endif
> > ```
> > 
> > `#define XRAY_HAS_TLS_ALIGNAS 0` is not needed as `#if 
> > XRAY_HAS_TLS_ALIGNAS` will evaluate to false anyway and `#define 
> > XRAY_HAS_TLS_ALIGNAS 1` is equivalent to `#define XRAY_HAS_TLS_ALIGNAS`. 
> > But it's just a matter of style.
> FWIW, I agree to this suggestion. I also prefer:
> 
> ```
> #if SANITIZER_NETBSD
> ...
> #else
> ...
> ```
> 
> But I do like the explicit definition of `XRAY_HAS_TLS_ALIGNAS`.
I've chosen the explicit method to match what's already done e.g. in 
`sanitizer_platform.h`. I'll swap the order.


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

https://reviews.llvm.org/D56000



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56000: [compiler-rt] [xray] Disable alignas() for thread_local objects on NetBSD

2018-12-22 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179414.
mgorny marked 2 inline comments as done.
mgorny added a comment.

Reordered.


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

https://reviews.llvm.org/D56000

Files:
  lib/xray/xray_basic_logging.cc
  lib/xray/xray_defs.h
  lib/xray/xray_fdr_logging.cc


Index: lib/xray/xray_fdr_logging.cc
===
--- lib/xray/xray_fdr_logging.cc
+++ lib/xray/xray_fdr_logging.cc
@@ -51,7 +51,7 @@
 // call so that it can be initialized on first use instead of as a global. We
 // force the alignment to 64-bytes for x86 cache line alignment, as this
 // structure is used in the hot path of implementation.
-struct alignas(64) ThreadLocalData {
+struct XRAY_TLS_ALIGNAS(64) ThreadLocalData {
   BufferQueue::Buffer Buffer{};
   BufferQueue *BQ = nullptr;
 
@@ -124,8 +124,10 @@
 // critical section, calling a function that might be XRay instrumented (and
 // thus in turn calling into malloc by virtue of registration of the
 // thread_local's destructor).
+#if XRAY_HAS_TLS_ALIGNAS
 static_assert(alignof(ThreadLocalData) >= 64,
   "ThreadLocalData must be cache line aligned.");
+#endif
 static ThreadLocalData &getThreadLocalData() {
   thread_local typename std::aligned_storage<
   sizeof(ThreadLocalData), alignof(ThreadLocalData)>::type TLDStorage{};
Index: lib/xray/xray_defs.h
===
--- lib/xray/xray_defs.h
+++ lib/xray/xray_defs.h
@@ -19,4 +19,14 @@
 #define XRAY_NEVER_INSTRUMENT
 #endif
 
+#if SANITIZER_NETBSD
+// NetBSD: thread_local is not aligned properly, and the code relying
+// on it segfaults
+#define XRAY_TLS_ALIGNAS(x)
+#define XRAY_HAS_TLS_ALIGNAS 0
+#else
+#define XRAY_TLS_ALIGNAS(x) alignas(x)
+#define XRAY_HAS_TLS_ALIGNAS 1
+#endif
+
 #endif  // XRAY_XRAY_DEFS_H
Index: lib/xray/xray_basic_logging.cc
===
--- lib/xray/xray_basic_logging.cc
+++ lib/xray/xray_basic_logging.cc
@@ -55,7 +55,7 @@
 
 static_assert(sizeof(StackEntry) == 16, "Wrong size for StackEntry");
 
-struct alignas(64) ThreadLocalData {
+struct XRAY_TLS_ALIGNAS(64) ThreadLocalData {
   void *InMemoryBuffer = nullptr;
   size_t BufferSize = 0;
   size_t BufferOffset = 0;


Index: lib/xray/xray_fdr_logging.cc
===
--- lib/xray/xray_fdr_logging.cc
+++ lib/xray/xray_fdr_logging.cc
@@ -51,7 +51,7 @@
 // call so that it can be initialized on first use instead of as a global. We
 // force the alignment to 64-bytes for x86 cache line alignment, as this
 // structure is used in the hot path of implementation.
-struct alignas(64) ThreadLocalData {
+struct XRAY_TLS_ALIGNAS(64) ThreadLocalData {
   BufferQueue::Buffer Buffer{};
   BufferQueue *BQ = nullptr;
 
@@ -124,8 +124,10 @@
 // critical section, calling a function that might be XRay instrumented (and
 // thus in turn calling into malloc by virtue of registration of the
 // thread_local's destructor).
+#if XRAY_HAS_TLS_ALIGNAS
 static_assert(alignof(ThreadLocalData) >= 64,
   "ThreadLocalData must be cache line aligned.");
+#endif
 static ThreadLocalData &getThreadLocalData() {
   thread_local typename std::aligned_storage<
   sizeof(ThreadLocalData), alignof(ThreadLocalData)>::type TLDStorage{};
Index: lib/xray/xray_defs.h
===
--- lib/xray/xray_defs.h
+++ lib/xray/xray_defs.h
@@ -19,4 +19,14 @@
 #define XRAY_NEVER_INSTRUMENT
 #endif
 
+#if SANITIZER_NETBSD
+// NetBSD: thread_local is not aligned properly, and the code relying
+// on it segfaults
+#define XRAY_TLS_ALIGNAS(x)
+#define XRAY_HAS_TLS_ALIGNAS 0
+#else
+#define XRAY_TLS_ALIGNAS(x) alignas(x)
+#define XRAY_HAS_TLS_ALIGNAS 1
+#endif
+
 #endif  // XRAY_XRAY_DEFS_H
Index: lib/xray/xray_basic_logging.cc
===
--- lib/xray/xray_basic_logging.cc
+++ lib/xray/xray_basic_logging.cc
@@ -55,7 +55,7 @@
 
 static_assert(sizeof(StackEntry) == 16, "Wrong size for StackEntry");
 
-struct alignas(64) ThreadLocalData {
+struct XRAY_TLS_ALIGNAS(64) ThreadLocalData {
   void *InMemoryBuffer = nullptr;
   size_t BufferSize = 0;
   size_t BufferOffset = 0;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56047: [Driver] Disable -faddrsig on Gentoo by default

2018-12-22 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: pcc, dyung, phosek.

Gentoo supports combining clang toolchain with GNU binutils, and many
users actually do that.  As -faddrsig is not supported by GNU strip,
this results in a lot of warnings.  Disable it by default and let users
enable it explicitly if they want it; with the intent of reevaluating
when the underlying feature becomes standarized.


Repository:
  rC Clang

https://reviews.llvm.org/D56047

Files:
  lib/Driver/ToolChains/Clang.cpp
  test/Driver/addrsig.c
  test/lit.cfg.py


Index: test/lit.cfg.py
===
--- test/lit.cfg.py
+++ test/lit.cfg.py
@@ -190,3 +190,6 @@
 macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config)
 if macOSSDKVersion is not None:
 config.available_features.add('macos-sdk-' + macOSSDKVersion)
+
+if os.path.exists('/etc/gentoo-release'):
+config.available_features.add('gentoo')
Index: test/Driver/addrsig.c
===
--- test/Driver/addrsig.c
+++ test/Driver/addrsig.c
@@ -1,3 +1,6 @@
+// Gentoo disables -faddrsig by default
+// XFAIL: gentoo
+
 // RUN: %clang -### -target x86_64-unknown-linux -c %s 2>&1 | FileCheck 
-check-prefix=ADDRSIG %s
 // RUN: %clang -### -target x86_64-pc-win32 -c %s 2>&1 | FileCheck 
-check-prefix=ADDRSIG %s
 // RUN: %clang -### -target x86_64-unknown-linux -fno-integrated-as -c %s 2>&1 
| FileCheck -check-prefix=NO-ADDRSIG %s
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -25,6 +25,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/ObjCRuntime.h"
 #include "clang/Basic/Version.h"
+#include "clang/Driver/Distro.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
@@ -5290,6 +5291,7 @@
 TC.getTriple().isOSBinFormatCOFF()) &&
   !TC.getTriple().isPS4() &&
   !TC.getTriple().isOSNetBSD() &&
+  !Distro(D.getVFS()).IsGentoo() &&
TC.useIntegratedAs()))
 CmdArgs.push_back("-faddrsig");
 


Index: test/lit.cfg.py
===
--- test/lit.cfg.py
+++ test/lit.cfg.py
@@ -190,3 +190,6 @@
 macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config)
 if macOSSDKVersion is not None:
 config.available_features.add('macos-sdk-' + macOSSDKVersion)
+
+if os.path.exists('/etc/gentoo-release'):
+config.available_features.add('gentoo')
Index: test/Driver/addrsig.c
===
--- test/Driver/addrsig.c
+++ test/Driver/addrsig.c
@@ -1,3 +1,6 @@
+// Gentoo disables -faddrsig by default
+// XFAIL: gentoo
+
 // RUN: %clang -### -target x86_64-unknown-linux -c %s 2>&1 | FileCheck -check-prefix=ADDRSIG %s
 // RUN: %clang -### -target x86_64-pc-win32 -c %s 2>&1 | FileCheck -check-prefix=ADDRSIG %s
 // RUN: %clang -### -target x86_64-unknown-linux -fno-integrated-as -c %s 2>&1 | FileCheck -check-prefix=NO-ADDRSIG %s
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -25,6 +25,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/ObjCRuntime.h"
 #include "clang/Basic/Version.h"
+#include "clang/Driver/Distro.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
@@ -5290,6 +5291,7 @@
 TC.getTriple().isOSBinFormatCOFF()) &&
   !TC.getTriple().isPS4() &&
   !TC.getTriple().isOSNetBSD() &&
+  !Distro(D.getVFS()).IsGentoo() &&
TC.useIntegratedAs()))
 CmdArgs.push_back("-faddrsig");
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56049: [compiler-rt] [xray] Detect MPROTECT and error out when it's enabled (on NetBSD)

2018-12-22 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, dberris.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek.

Add a CheckMPROTECT() routine to detect when pax MPROTECT is enabled
on NetBSD, and error xray out when it is.  The solution is adapted
from existing CheckASLR().


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56049

Files:
  lib/sanitizer_common/sanitizer_common.h
  lib/sanitizer_common/sanitizer_fuchsia.cc
  lib/sanitizer_common/sanitizer_linux.cc
  lib/sanitizer_common/sanitizer_mac.cc
  lib/sanitizer_common/sanitizer_rtems.cc
  lib/sanitizer_common/sanitizer_win.cc
  lib/xray/xray_init.cc

Index: lib/xray/xray_init.cc
===
--- lib/xray/xray_init.cc
+++ lib/xray/xray_init.cc
@@ -67,6 +67,9 @@
   if (atomic_load(&XRayInitialized, memory_order_acquire))
 return;
 
+  // XRAY is not compatible with pax MPROTECT
+  CheckMPROTECT();
+
   if (!atomic_load(&XRayFlagsInitialized, memory_order_acquire)) {
 initializeFlags();
 atomic_store(&XRayFlagsInitialized, true, memory_order_release);
Index: lib/sanitizer_common/sanitizer_win.cc
===
--- lib/sanitizer_common/sanitizer_win.cc
+++ lib/sanitizer_common/sanitizer_win.cc
@@ -1016,6 +1016,10 @@
   // Do nothing
 }
 
+void CheckMPROTECT() {
+  // Do nothing
+}
+
 char **GetArgv() {
   // FIXME: Actually implement this function.
   return 0;
Index: lib/sanitizer_common/sanitizer_rtems.cc
===
--- lib/sanitizer_common/sanitizer_rtems.cc
+++ lib/sanitizer_common/sanitizer_rtems.cc
@@ -98,6 +98,7 @@
 void InitializePlatformEarly() {}
 void MaybeReexec() {}
 void CheckASLR() {}
+void CheckMPROTECT() {}
 void DisableCoreDumperIfNecessary() {}
 void InstallDeadlySignalHandlers(SignalHandlerType handler) {}
 void SetAlternateSignalStack() {}
Index: lib/sanitizer_common/sanitizer_mac.cc
===
--- lib/sanitizer_common/sanitizer_mac.cc
+++ lib/sanitizer_common/sanitizer_mac.cc
@@ -377,6 +377,10 @@
   // Do nothing
 }
 
+void CheckMPROTECT() {
+  // Do nothing
+}
+
 uptr GetPageSize() {
   return sysconf(_SC_PAGESIZE);
 }
Index: lib/sanitizer_common/sanitizer_linux.cc
===
--- lib/sanitizer_common/sanitizer_linux.cc
+++ lib/sanitizer_common/sanitizer_linux.cc
@@ -2023,6 +2023,30 @@
 #endif
 }
 
+void CheckMPROTECT() {
+#if SANITIZER_NETBSD
+  int mib[3];
+  int paxflags;
+  uptr len = sizeof(paxflags);
+
+  mib[0] = CTL_PROC;
+  mib[1] = internal_getpid();
+  mib[2] = PROC_PID_PAXFLAGS;
+
+  if (UNLIKELY(internal_sysctl(mib, 3, &paxflags, &len, NULL, 0) == -1)) {
+Printf("sysctl failed\n");
+Die();
+  }
+
+  if (UNLIKELY(paxflags & CTL_PROC_PAXFLAGS_MPROTECT)) {
+Printf("This sanitizer is not compatible with enabled MPROTECT\n");
+Die();
+  }
+#else
+  // Do nothing
+#endif
+}
+
 void PrintModuleMap() { }
 
 void CheckNoDeepBind(const char *filename, int flag) {
Index: lib/sanitizer_common/sanitizer_fuchsia.cc
===
--- lib/sanitizer_common/sanitizer_fuchsia.cc
+++ lib/sanitizer_common/sanitizer_fuchsia.cc
@@ -89,6 +89,7 @@
 void InitializePlatformEarly() {}
 void MaybeReexec() {}
 void CheckASLR() {}
+void CheckMPROTECT() {}
 void PlatformPrepareForSandboxing(__sanitizer_sandbox_arguments *args) {}
 void DisableCoreDumperIfNecessary() {}
 void InstallDeadlySignalHandlers(SignalHandlerType handler) {}
Index: lib/sanitizer_common/sanitizer_common.h
===
--- lib/sanitizer_common/sanitizer_common.h
+++ lib/sanitizer_common/sanitizer_common.h
@@ -223,6 +223,7 @@
 u32 GetUid();
 void ReExec();
 void CheckASLR();
+void CheckMPROTECT();
 char **GetArgv();
 char **GetEnviron();
 void PrintCmdline();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56047: [Driver] Disable -faddrsig on Gentoo by default

2018-12-22 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

In D56047#1340303 , @phosek wrote:

> Just a comment regarding the description, are you sure it's GNU strip and not 
> as?


Yes. https://bugs.gentoo.org/667854


Repository:
  rC Clang

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

https://reviews.llvm.org/D56047



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56047: [Driver] Disable -faddrsig on Gentoo by default

2018-12-23 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

In D56047#1340337 , @phosek wrote:

> LGTM, would it be possible to also include https://bugs.gentoo.org/667854 in 
> the commit message for reference?


Done, and thanks for the review.


Repository:
  rC Clang

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

https://reviews.llvm.org/D56047



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56024: [clang] [Distro] Support detecting Gentoo

2018-12-23 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL350027: [Distro] Support detecting Gentoo (authored by 
mgorny, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D56024?vs=179413&id=179441#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D56024

Files:
  cfe/trunk/include/clang/Driver/Distro.h
  cfe/trunk/lib/Driver/Distro.cpp
  cfe/trunk/unittests/Driver/DistroTest.cpp

Index: cfe/trunk/include/clang/Driver/Distro.h
===
--- cfe/trunk/include/clang/Driver/Distro.h
+++ cfe/trunk/include/clang/Driver/Distro.h
@@ -39,6 +39,7 @@
 RHEL6,
 RHEL7,
 Fedora,
+Gentoo,
 OpenSUSE,
 UbuntuHardy,
 UbuntuIntrepid,
@@ -123,6 +124,10 @@
 return DistroVal == AlpineLinux;
   }
 
+  bool IsGentoo() const {
+return DistroVal == Gentoo;
+  }
+
   /// @}
 };
 
Index: cfe/trunk/lib/Driver/Distro.cpp
===
--- cfe/trunk/lib/Driver/Distro.cpp
+++ cfe/trunk/lib/Driver/Distro.cpp
@@ -138,6 +138,9 @@
   if (VFS.exists("/etc/arch-release"))
 return Distro::ArchLinux;
 
+  if (VFS.exists("/etc/gentoo-release"))
+return Distro::Gentoo;
+
   return Distro::UnknownDistro;
 }
 
Index: cfe/trunk/unittests/Driver/DistroTest.cpp
===
--- cfe/trunk/unittests/Driver/DistroTest.cpp
+++ cfe/trunk/unittests/Driver/DistroTest.cpp
@@ -51,6 +51,7 @@
   ASSERT_FALSE(UbuntuTrusty.IsRedhat());
   ASSERT_FALSE(UbuntuTrusty.IsOpenSUSE());
   ASSERT_FALSE(UbuntuTrusty.IsDebian());
+  ASSERT_FALSE(UbuntuTrusty.IsGentoo());
 
   llvm::vfs::InMemoryFileSystem UbuntuYakketyFileSystem;
   UbuntuYakketyFileSystem.addFile("/etc/debian_version", 0,
@@ -80,6 +81,7 @@
   ASSERT_FALSE(UbuntuYakkety.IsRedhat());
   ASSERT_FALSE(UbuntuYakkety.IsOpenSUSE());
   ASSERT_FALSE(UbuntuYakkety.IsDebian());
+  ASSERT_FALSE(UbuntuYakkety.IsGentoo());
 }
 
 TEST(DistroTest, DetectRedhat) {
@@ -114,6 +116,7 @@
   ASSERT_TRUE(Fedora25.IsRedhat());
   ASSERT_FALSE(Fedora25.IsOpenSUSE());
   ASSERT_FALSE(Fedora25.IsDebian());
+  ASSERT_FALSE(Fedora25.IsGentoo());
 
   llvm::vfs::InMemoryFileSystem CentOS7FileSystem;
   CentOS7FileSystem.addFile("/etc/system-release-cpe", 0,
@@ -150,6 +153,7 @@
   ASSERT_TRUE(CentOS7.IsRedhat());
   ASSERT_FALSE(CentOS7.IsOpenSUSE());
   ASSERT_FALSE(CentOS7.IsDebian());
+  ASSERT_FALSE(CentOS7.IsGentoo());
 }
 
 TEST(DistroTest, DetectOpenSUSE) {
@@ -177,6 +181,7 @@
   ASSERT_FALSE(OpenSUSELeap421.IsRedhat());
   ASSERT_TRUE(OpenSUSELeap421.IsOpenSUSE());
   ASSERT_FALSE(OpenSUSELeap421.IsDebian());
+  ASSERT_FALSE(OpenSUSELeap421.IsGentoo());
 
   llvm::vfs::InMemoryFileSystem OpenSUSE132FileSystem;
   OpenSUSE132FileSystem.addFile("/etc/SuSE-release", 0,
@@ -202,6 +207,7 @@
   ASSERT_FALSE(OpenSUSE132.IsRedhat());
   ASSERT_TRUE(OpenSUSE132.IsOpenSUSE());
   ASSERT_FALSE(OpenSUSE132.IsDebian());
+  ASSERT_FALSE(OpenSUSE132.IsGentoo());
 
   llvm::vfs::InMemoryFileSystem SLES10FileSystem;
   SLES10FileSystem.addFile("/etc/SuSE-release", 0,
@@ -218,6 +224,7 @@
   ASSERT_FALSE(SLES10.IsRedhat());
   ASSERT_FALSE(SLES10.IsOpenSUSE());
   ASSERT_FALSE(SLES10.IsDebian());
+  ASSERT_FALSE(SLES10.IsGentoo());
 }
 
 TEST(DistroTest, DetectDebian) {
@@ -240,6 +247,7 @@
   ASSERT_FALSE(DebianJessie.IsRedhat());
   ASSERT_FALSE(DebianJessie.IsOpenSUSE());
   ASSERT_TRUE(DebianJessie.IsDebian());
+  ASSERT_FALSE(DebianJessie.IsGentoo());
 
   llvm::vfs::InMemoryFileSystem DebianStretchSidFileSystem;
   DebianStretchSidFileSystem.addFile("/etc/debian_version", 0,
@@ -258,6 +266,7 @@
   ASSERT_FALSE(DebianStretchSid.IsRedhat());
   ASSERT_FALSE(DebianStretchSid.IsOpenSUSE());
   ASSERT_TRUE(DebianStretchSid.IsDebian());
+  ASSERT_FALSE(DebianStretchSid.IsGentoo());
 }
 
 TEST(DistroTest, DetectExherbo) {
@@ -279,6 +288,7 @@
   ASSERT_FALSE(Exherbo.IsRedhat());
   ASSERT_FALSE(Exherbo.IsOpenSUSE());
   ASSERT_FALSE(Exherbo.IsDebian());
+  ASSERT_FALSE(Exherbo.IsGentoo());
 }
 
 TEST(DistroTest, DetectArchLinux) {
@@ -300,6 +310,32 @@
   ASSERT_FALSE(ArchLinux.IsRedhat());
   ASSERT_FALSE(ArchLinux.IsOpenSUSE());
   ASSERT_FALSE(ArchLinux.IsDebian());
+  ASSERT_FALSE(ArchLinux.IsGentoo());
+}
+
+TEST(DistroTest, DetectGentoo) {
+  llvm::vfs::InMemoryFileSystem GentooFileSystem;
+  GentooFileSystem.addFile(
+  "/etc/gentoo-release", 0,
+  llvm::MemoryBuffer::getMemBuffer("Gentoo Base System release 2.6"));
+  GentooFileSystem.addFile(
+  "/etc/os-release", 0,
+  llvm::MemoryBuffer::getMemBuffer(
+  "NAME=Gentoo\n"
+  "ID=gentoo\n"
+  "PRETTY_NAME=\"Gentoo/Linux\"\n"
+  "ANSI_COLOR=\"1;32\"\n"
+  "HOME_URL=\"https://www.gentoo.org/\"\n";
+  "SUPPORT_URL=\"https://www.gentoo.org/support/\"\n";
+  

[PATCH] D56047: [Driver] Disable -faddrsig on Gentoo by default

2018-12-23 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL350028: [Driver] Disable -faddrsig on Gentoo by default 
(authored by mgorny, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D56047?vs=179415&id=179442#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D56047

Files:
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/test/Driver/addrsig.c
  cfe/trunk/test/lit.cfg.py


Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -25,6 +25,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/ObjCRuntime.h"
 #include "clang/Basic/Version.h"
+#include "clang/Driver/Distro.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
@@ -5290,6 +5291,7 @@
 TC.getTriple().isOSBinFormatCOFF()) &&
   !TC.getTriple().isPS4() &&
   !TC.getTriple().isOSNetBSD() &&
+  !Distro(D.getVFS()).IsGentoo() &&
TC.useIntegratedAs()))
 CmdArgs.push_back("-faddrsig");
 
Index: cfe/trunk/test/lit.cfg.py
===
--- cfe/trunk/test/lit.cfg.py
+++ cfe/trunk/test/lit.cfg.py
@@ -190,3 +190,6 @@
 macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config)
 if macOSSDKVersion is not None:
 config.available_features.add('macos-sdk-' + macOSSDKVersion)
+
+if os.path.exists('/etc/gentoo-release'):
+config.available_features.add('gentoo')
Index: cfe/trunk/test/Driver/addrsig.c
===
--- cfe/trunk/test/Driver/addrsig.c
+++ cfe/trunk/test/Driver/addrsig.c
@@ -1,3 +1,6 @@
+// Gentoo disables -faddrsig by default
+// XFAIL: gentoo
+
 // RUN: %clang -### -target x86_64-unknown-linux -c %s 2>&1 | FileCheck 
-check-prefix=ADDRSIG %s
 // RUN: %clang -### -target x86_64-pc-win32 -c %s 2>&1 | FileCheck 
-check-prefix=ADDRSIG %s
 // RUN: %clang -### -target x86_64-unknown-linux -fno-integrated-as -c %s 2>&1 
| FileCheck -check-prefix=NO-ADDRSIG %s


Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -25,6 +25,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/ObjCRuntime.h"
 #include "clang/Basic/Version.h"
+#include "clang/Driver/Distro.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
@@ -5290,6 +5291,7 @@
 TC.getTriple().isOSBinFormatCOFF()) &&
   !TC.getTriple().isPS4() &&
   !TC.getTriple().isOSNetBSD() &&
+  !Distro(D.getVFS()).IsGentoo() &&
TC.useIntegratedAs()))
 CmdArgs.push_back("-faddrsig");
 
Index: cfe/trunk/test/lit.cfg.py
===
--- cfe/trunk/test/lit.cfg.py
+++ cfe/trunk/test/lit.cfg.py
@@ -190,3 +190,6 @@
 macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config)
 if macOSSDKVersion is not None:
 config.available_features.add('macos-sdk-' + macOSSDKVersion)
+
+if os.path.exists('/etc/gentoo-release'):
+config.available_features.add('gentoo')
Index: cfe/trunk/test/Driver/addrsig.c
===
--- cfe/trunk/test/Driver/addrsig.c
+++ cfe/trunk/test/Driver/addrsig.c
@@ -1,3 +1,6 @@
+// Gentoo disables -faddrsig by default
+// XFAIL: gentoo
+
 // RUN: %clang -### -target x86_64-unknown-linux -c %s 2>&1 | FileCheck -check-prefix=ADDRSIG %s
 // RUN: %clang -### -target x86_64-pc-win32 -c %s 2>&1 | FileCheck -check-prefix=ADDRSIG %s
 // RUN: %clang -### -target x86_64-unknown-linux -fno-integrated-as -c %s 2>&1 | FileCheck -check-prefix=NO-ADDRSIG %s
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56000: [compiler-rt] [xray] Disable alignas() for thread_local objects on NetBSD

2018-12-23 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL350029: [xray] Disable alignas() for thread_local objects on 
NetBSD (authored by mgorny, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D56000?vs=179414&id=179443#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D56000

Files:
  compiler-rt/trunk/lib/xray/xray_basic_logging.cc
  compiler-rt/trunk/lib/xray/xray_defs.h
  compiler-rt/trunk/lib/xray/xray_fdr_logging.cc


Index: compiler-rt/trunk/lib/xray/xray_basic_logging.cc
===
--- compiler-rt/trunk/lib/xray/xray_basic_logging.cc
+++ compiler-rt/trunk/lib/xray/xray_basic_logging.cc
@@ -55,7 +55,7 @@
 
 static_assert(sizeof(StackEntry) == 16, "Wrong size for StackEntry");
 
-struct alignas(64) ThreadLocalData {
+struct XRAY_TLS_ALIGNAS(64) ThreadLocalData {
   void *InMemoryBuffer = nullptr;
   size_t BufferSize = 0;
   size_t BufferOffset = 0;
Index: compiler-rt/trunk/lib/xray/xray_defs.h
===
--- compiler-rt/trunk/lib/xray/xray_defs.h
+++ compiler-rt/trunk/lib/xray/xray_defs.h
@@ -19,4 +19,14 @@
 #define XRAY_NEVER_INSTRUMENT
 #endif
 
+#if SANITIZER_NETBSD
+// NetBSD: thread_local is not aligned properly, and the code relying
+// on it segfaults
+#define XRAY_TLS_ALIGNAS(x)
+#define XRAY_HAS_TLS_ALIGNAS 0
+#else
+#define XRAY_TLS_ALIGNAS(x) alignas(x)
+#define XRAY_HAS_TLS_ALIGNAS 1
+#endif
+
 #endif  // XRAY_XRAY_DEFS_H
Index: compiler-rt/trunk/lib/xray/xray_fdr_logging.cc
===
--- compiler-rt/trunk/lib/xray/xray_fdr_logging.cc
+++ compiler-rt/trunk/lib/xray/xray_fdr_logging.cc
@@ -51,7 +51,7 @@
 // call so that it can be initialized on first use instead of as a global. We
 // force the alignment to 64-bytes for x86 cache line alignment, as this
 // structure is used in the hot path of implementation.
-struct alignas(64) ThreadLocalData {
+struct XRAY_TLS_ALIGNAS(64) ThreadLocalData {
   BufferQueue::Buffer Buffer{};
   BufferQueue *BQ = nullptr;
 
@@ -124,8 +124,10 @@
 // critical section, calling a function that might be XRay instrumented (and
 // thus in turn calling into malloc by virtue of registration of the
 // thread_local's destructor).
+#if XRAY_HAS_TLS_ALIGNAS
 static_assert(alignof(ThreadLocalData) >= 64,
   "ThreadLocalData must be cache line aligned.");
+#endif
 static ThreadLocalData &getThreadLocalData() {
   thread_local typename std::aligned_storage<
   sizeof(ThreadLocalData), alignof(ThreadLocalData)>::type TLDStorage{};


Index: compiler-rt/trunk/lib/xray/xray_basic_logging.cc
===
--- compiler-rt/trunk/lib/xray/xray_basic_logging.cc
+++ compiler-rt/trunk/lib/xray/xray_basic_logging.cc
@@ -55,7 +55,7 @@
 
 static_assert(sizeof(StackEntry) == 16, "Wrong size for StackEntry");
 
-struct alignas(64) ThreadLocalData {
+struct XRAY_TLS_ALIGNAS(64) ThreadLocalData {
   void *InMemoryBuffer = nullptr;
   size_t BufferSize = 0;
   size_t BufferOffset = 0;
Index: compiler-rt/trunk/lib/xray/xray_defs.h
===
--- compiler-rt/trunk/lib/xray/xray_defs.h
+++ compiler-rt/trunk/lib/xray/xray_defs.h
@@ -19,4 +19,14 @@
 #define XRAY_NEVER_INSTRUMENT
 #endif
 
+#if SANITIZER_NETBSD
+// NetBSD: thread_local is not aligned properly, and the code relying
+// on it segfaults
+#define XRAY_TLS_ALIGNAS(x)
+#define XRAY_HAS_TLS_ALIGNAS 0
+#else
+#define XRAY_TLS_ALIGNAS(x) alignas(x)
+#define XRAY_HAS_TLS_ALIGNAS 1
+#endif
+
 #endif  // XRAY_XRAY_DEFS_H
Index: compiler-rt/trunk/lib/xray/xray_fdr_logging.cc
===
--- compiler-rt/trunk/lib/xray/xray_fdr_logging.cc
+++ compiler-rt/trunk/lib/xray/xray_fdr_logging.cc
@@ -51,7 +51,7 @@
 // call so that it can be initialized on first use instead of as a global. We
 // force the alignment to 64-bytes for x86 cache line alignment, as this
 // structure is used in the hot path of implementation.
-struct alignas(64) ThreadLocalData {
+struct XRAY_TLS_ALIGNAS(64) ThreadLocalData {
   BufferQueue::Buffer Buffer{};
   BufferQueue *BQ = nullptr;
 
@@ -124,8 +124,10 @@
 // critical section, calling a function that might be XRay instrumented (and
 // thus in turn calling into malloc by virtue of registration of the
 // thread_local's destructor).
+#if XRAY_HAS_TLS_ALIGNAS
 static_assert(alignof(ThreadLocalData) >= 64,
   "ThreadLocalData must be cache line aligned.");
+#endif
 static ThreadLocalData &getThreadLocalData() {
   thread_local typename std::aligned_storage<
   sizeof(ThreadLocalData), alignof(ThreadLocalData)>::type TLDStorage{};
___
cfe-commits maili

[PATCH] D56049: [compiler-rt] [xray] Detect MPROTECT and error out when it's enabled (on NetBSD)

2018-12-23 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL350030: [xray] Detect MPROTECT and error out when it's 
enabled (on NetBSD) (authored by mgorny, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D56049?vs=179419&id=179444#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D56049

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
  compiler-rt/trunk/lib/xray/xray_init.cc

Index: compiler-rt/trunk/lib/xray/xray_init.cc
===
--- compiler-rt/trunk/lib/xray/xray_init.cc
+++ compiler-rt/trunk/lib/xray/xray_init.cc
@@ -67,6 +67,9 @@
   if (atomic_load(&XRayInitialized, memory_order_acquire))
 return;
 
+  // XRAY is not compatible with PaX MPROTECT
+  CheckMPROTECT();
+
   if (!atomic_load(&XRayFlagsInitialized, memory_order_acquire)) {
 initializeFlags();
 atomic_store(&XRayFlagsInitialized, true, memory_order_release);
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc
@@ -89,6 +89,7 @@
 void InitializePlatformEarly() {}
 void MaybeReexec() {}
 void CheckASLR() {}
+void CheckMPROTECT() {}
 void PlatformPrepareForSandboxing(__sanitizer_sandbox_arguments *args) {}
 void DisableCoreDumperIfNecessary() {}
 void InstallDeadlySignalHandlers(SignalHandlerType handler) {}
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
@@ -377,6 +377,10 @@
   // Do nothing
 }
 
+void CheckMPROTECT() {
+  // Do nothing
+}
+
 uptr GetPageSize() {
   return sysconf(_SC_PAGESIZE);
 }
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
@@ -1016,6 +1016,10 @@
   // Do nothing
 }
 
+void CheckMPROTECT() {
+  // Do nothing
+}
+
 char **GetArgv() {
   // FIXME: Actually implement this function.
   return 0;
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
@@ -2023,6 +2023,30 @@
 #endif
 }
 
+void CheckMPROTECT() {
+#if SANITIZER_NETBSD
+  int mib[3];
+  int paxflags;
+  uptr len = sizeof(paxflags);
+
+  mib[0] = CTL_PROC;
+  mib[1] = internal_getpid();
+  mib[2] = PROC_PID_PAXFLAGS;
+
+  if (UNLIKELY(internal_sysctl(mib, 3, &paxflags, &len, NULL, 0) == -1)) {
+Printf("sysctl failed\n");
+Die();
+  }
+
+  if (UNLIKELY(paxflags & CTL_PROC_PAXFLAGS_MPROTECT)) {
+Printf("This sanitizer is not compatible with enabled MPROTECT\n");
+Die();
+  }
+#else
+  // Do nothing
+#endif
+}
+
 void PrintModuleMap() { }
 
 void CheckNoDeepBind(const char *filename, int flag) {
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
@@ -223,6 +223,7 @@
 u32 GetUid();
 void ReExec();
 void CheckASLR();
+void CheckMPROTECT();
 char **GetArgv();
 char **GetEnviron();
 void PrintCmdline();
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc
@@ -98,6 +98,7 @@
 void InitializePlatformEarly() {}
 void MaybeReexec() {}
 void CheckASLR() {}
+void CheckMPROTECT() {}
 void DisableCoreDumperIfNecessary() {}
 void InstallDeadlySignalHandlers(SignalHandlerType handler) {}
 void SetAlternateSignalStack() {}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56061: [clang-tools-extra] [clangd] Fix detecting atomics in stand-alone builds

2018-12-23 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: bkramer, sdardis, sammccall, ilya-biryukov.
Herald added subscribers: kadircet, jfb, arphaman, jkorous, MaskRay, ioeric.

Include CheckAtomic CMake module from LLVM in order to detect support
for atomics when building stand-alone.  Otherwise,
the HAVE_CXX_ATOMICS64_WITHOUT_LIB variable is undefined and clangd
wrongly attempts to link -latomic on systems not using the library.

Original bug report: https://bugs.gentoo.org/667016


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D56061

Files:
  clangd/CMakeLists.txt


Index: clangd/CMakeLists.txt
===
--- clangd/CMakeLists.txt
+++ clangd/CMakeLists.txt
@@ -2,6 +2,11 @@
   Support
   )
 
+if(CLANG_BUILT_STANDALONE)
+  # needed to get HAVE_CXX_ATOMICS64_WITHOUT_LIB defined
+  include(CheckAtomic)
+endif()
+
 set(CLANGD_ATOMIC_LIB "")
 if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
   list(APPEND CLANGD_ATOMIC_LIB "atomic")


Index: clangd/CMakeLists.txt
===
--- clangd/CMakeLists.txt
+++ clangd/CMakeLists.txt
@@ -2,6 +2,11 @@
   Support
   )
 
+if(CLANG_BUILT_STANDALONE)
+  # needed to get HAVE_CXX_ATOMICS64_WITHOUT_LIB defined
+  include(CheckAtomic)
+endif()
+
 set(CLANGD_ATOMIC_LIB "")
 if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
   list(APPEND CLANGD_ATOMIC_LIB "atomic")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47817: [compiler-rt] [sanitizer_common] Fix using libtirpc on Linux

2018-12-23 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179453.
mgorny retitled this revision from "[sanitizer_common] Fix using libtirpc on 
Linux" to "[compiler-rt] [sanitizer_common] Fix using libtirpc on Linux".
mgorny edited the summary of this revision.
mgorny added a reviewer: Lekensteyn.
mgorny added a comment.
Herald added a subscriber: dberris.

Ok, I give up. Here's a version using `find_package()`. Can we finally get this 
fixed?


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

https://reviews.llvm.org/D47817

Files:
  cmake/Modules/FindLibtirpc.cmake
  lib/sanitizer_common/CMakeLists.txt
  lib/sanitizer_common/sanitizer_platform_limits_posix.cc


Index: lib/sanitizer_common/sanitizer_platform_limits_posix.cc
===
--- lib/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ lib/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -114,8 +114,6 @@
 #include 
 #if HAVE_RPC_XDR_H
 # include 
-#elif HAVE_TIRPC_RPC_XDR_H
-# include 
 #endif
 #include 
 #include 
@@ -1210,7 +1208,7 @@
 CHECK_SIZE_AND_OFFSET(group, gr_gid);
 CHECK_SIZE_AND_OFFSET(group, gr_mem);
 
-#if HAVE_RPC_XDR_H || HAVE_TIRPC_RPC_XDR_H
+#if HAVE_RPC_XDR_H
 CHECK_TYPE_SIZE(XDR);
 CHECK_SIZE_AND_OFFSET(XDR, x_op);
 CHECK_SIZE_AND_OFFSET(XDR, x_ops);
Index: lib/sanitizer_common/CMakeLists.txt
===
--- lib/sanitizer_common/CMakeLists.txt
+++ lib/sanitizer_common/CMakeLists.txt
@@ -193,9 +193,12 @@
 
 set(SANITIZER_COMMON_DEFINITIONS)
 
-include(CheckIncludeFile)
-append_have_file_definition(rpc/xdr.h HAVE_RPC_XDR_H 
SANITIZER_COMMON_DEFINITIONS)
-append_have_file_definition(tirpc/rpc/xdr.h HAVE_TIRPC_RPC_XDR_H 
SANITIZER_COMMON_DEFINITIONS)
+find_package(Libtirpc)
+
+if (Libtirpc_FOUND)
+  include_directories(${Libtirpc_INCLUDE_DIRS})
+  list(APPEND SANITIZER_COMMON_DEFINITIONS HAVE_RPC_XDR_H=1)
+endif()
 
 set(SANITIZER_CFLAGS ${SANITIZER_COMMON_CFLAGS})
 append_rtti_flag(OFF SANITIZER_CFLAGS)
Index: cmake/Modules/FindLibtirpc.cmake
===
--- /dev/null
+++ cmake/Modules/FindLibtirpc.cmake
@@ -0,0 +1,22 @@
+# CMake find_package() Module for libtirpc
+#
+# Example usage:
+#
+# find_package(Libtirpc)
+#
+# If successful the following variables will be defined
+# Libtirpc_FOUND
+# Libtirpc_INCLUDE_DIRS
+
+find_path(Libtirpc_INCLUDE_DIR
+  NAMES rpc/xdr.h
+  PATH_SUFFIXES tirpc
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Libtirpc
+   REQUIRED_VARS Libtirpc_INCLUDE_DIR)
+
+if(Libtirpc_FOUND)
+  set(Libtirpc_INCLUDE_DIRS ${Libtirpc_INCLUDE_DIR})
+endif()


Index: lib/sanitizer_common/sanitizer_platform_limits_posix.cc
===
--- lib/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ lib/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -114,8 +114,6 @@
 #include 
 #if HAVE_RPC_XDR_H
 # include 
-#elif HAVE_TIRPC_RPC_XDR_H
-# include 
 #endif
 #include 
 #include 
@@ -1210,7 +1208,7 @@
 CHECK_SIZE_AND_OFFSET(group, gr_gid);
 CHECK_SIZE_AND_OFFSET(group, gr_mem);
 
-#if HAVE_RPC_XDR_H || HAVE_TIRPC_RPC_XDR_H
+#if HAVE_RPC_XDR_H
 CHECK_TYPE_SIZE(XDR);
 CHECK_SIZE_AND_OFFSET(XDR, x_op);
 CHECK_SIZE_AND_OFFSET(XDR, x_ops);
Index: lib/sanitizer_common/CMakeLists.txt
===
--- lib/sanitizer_common/CMakeLists.txt
+++ lib/sanitizer_common/CMakeLists.txt
@@ -193,9 +193,12 @@
 
 set(SANITIZER_COMMON_DEFINITIONS)
 
-include(CheckIncludeFile)
-append_have_file_definition(rpc/xdr.h HAVE_RPC_XDR_H SANITIZER_COMMON_DEFINITIONS)
-append_have_file_definition(tirpc/rpc/xdr.h HAVE_TIRPC_RPC_XDR_H SANITIZER_COMMON_DEFINITIONS)
+find_package(Libtirpc)
+
+if (Libtirpc_FOUND)
+  include_directories(${Libtirpc_INCLUDE_DIRS})
+  list(APPEND SANITIZER_COMMON_DEFINITIONS HAVE_RPC_XDR_H=1)
+endif()
 
 set(SANITIZER_CFLAGS ${SANITIZER_COMMON_CFLAGS})
 append_rtti_flag(OFF SANITIZER_CFLAGS)
Index: cmake/Modules/FindLibtirpc.cmake
===
--- /dev/null
+++ cmake/Modules/FindLibtirpc.cmake
@@ -0,0 +1,22 @@
+# CMake find_package() Module for libtirpc
+#
+# Example usage:
+#
+# find_package(Libtirpc)
+#
+# If successful the following variables will be defined
+# Libtirpc_FOUND
+# Libtirpc_INCLUDE_DIRS
+
+find_path(Libtirpc_INCLUDE_DIR
+  NAMES rpc/xdr.h
+  PATH_SUFFIXES tirpc
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Libtirpc
+	REQUIRED_VARS Libtirpc_INCLUDE_DIR)
+
+if(Libtirpc_FOUND)
+  set(Libtirpc_INCLUDE_DIRS ${Libtirpc_INCLUDE_DIR})
+endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47819: [compiler-rt] [test] Support using libtirpc on Linux

2018-12-23 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179454.
mgorny retitled this revision from "[test] Support using libtirpc on Linux" to 
"[compiler-rt] [test] Support using libtirpc on Linux".
mgorny edited the summary of this revision.
mgorny added a reviewer: Lekensteyn.
mgorny set the repository for this revision to rCRT Compiler Runtime.
mgorny added a comment.
Herald added a subscriber: dberris.

Updated to use `find_package()`.


Repository:
  rCRT Compiler Runtime

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

https://reviews.llvm.org/D47819

Files:
  cmake/base-config-ix.cmake
  lib/sanitizer_common/CMakeLists.txt
  test/msan/lit.cfg
  test/msan/lit.site.cfg.in
  test/tsan/lit.cfg
  test/tsan/lit.site.cfg.in


Index: test/tsan/lit.site.cfg.in
===
--- test/tsan/lit.site.cfg.in
+++ test/tsan/lit.site.cfg.in
@@ -6,6 +6,7 @@
 config.apple_platform = "@TSAN_TEST_APPLE_PLATFORM@"
 config.target_cflags = "@TSAN_TEST_TARGET_CFLAGS@"
 config.target_arch = "@TSAN_TEST_TARGET_ARCH@"
+config.libtirpc_include_dirs = "@Libtirpc_INCLUDE_DIRS@"
 
 # Load common config for all compiler-rt lit tests.
 lit_config.load_config(config, 
"@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
Index: test/tsan/lit.cfg
===
--- test/tsan/lit.cfg
+++ test/tsan/lit.cfg
@@ -49,7 +49,8 @@
   [config.target_cflags] +
   config.debug_info_flags +
   extra_cflags +
-  ["-I%s" % tsan_incdir])
+  ["-I%s" % tsan_incdir] +
+  [("-I" + x) for x in config.libtirpc_include_dirs])
 clang_tsan_cxxflags = config.cxx_mode_flags + clang_tsan_cflags + 
["-std=c++11"] + ["-I%s" % tsan_incdir]
 # Add additional flags if we're using instrumented libc++.
 # Instrumented libcxx currently not supported on Darwin.
Index: test/msan/lit.site.cfg.in
===
--- test/msan/lit.site.cfg.in
+++ test/msan/lit.site.cfg.in
@@ -6,6 +6,7 @@
 config.target_arch = "@MSAN_TEST_TARGET_ARCH@"
 config.use_lld = @MSAN_TEST_USE_LLD@
 config.use_thinlto = @MSAN_TEST_USE_THINLTO@
+config.libtirpc_include_dirs = "@Libtirpc_INCLUDE_DIRS@"
 
 # Load common config for all compiler-rt lit tests.
 lit_config.load_config(config, 
"@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
Index: test/msan/lit.cfg
===
--- test/msan/lit.cfg
+++ test/msan/lit.cfg
@@ -14,7 +14,8 @@
   "-fno-omit-frame-pointer",
   "-fno-optimize-sibling-calls"] +
   [config.target_cflags] +
-  config.debug_info_flags)
+  config.debug_info_flags +
+  [("-I" + x) for x in config.libtirpc_include_dirs])
 # Some Msan tests leverage backtrace() which requires libexecinfo on FreeBSD.
 if config.host_os == 'FreeBSD':
   clang_msan_cflags += ["-lexecinfo", "-fPIC"]
Index: lib/sanitizer_common/CMakeLists.txt
===
--- lib/sanitizer_common/CMakeLists.txt
+++ lib/sanitizer_common/CMakeLists.txt
@@ -193,8 +193,6 @@
 
 set(SANITIZER_COMMON_DEFINITIONS)
 
-find_package(Libtirpc)
-
 if (Libtirpc_FOUND)
   include_directories(${Libtirpc_INCLUDE_DIRS})
   list(APPEND SANITIZER_COMMON_DEFINITIONS HAVE_RPC_XDR_H=1)
Index: cmake/base-config-ix.cmake
===
--- cmake/base-config-ix.cmake
+++ cmake/base-config-ix.cmake
@@ -8,6 +8,9 @@
 
 check_include_file(unwind.h HAVE_UNWIND_H)
 
+# used in sanitizer_common and tests
+find_package(Libtirpc)
+
 # Top level target used to build all compiler-rt libraries.
 add_custom_target(compiler-rt ALL)
 add_custom_target(install-compiler-rt)


Index: test/tsan/lit.site.cfg.in
===
--- test/tsan/lit.site.cfg.in
+++ test/tsan/lit.site.cfg.in
@@ -6,6 +6,7 @@
 config.apple_platform = "@TSAN_TEST_APPLE_PLATFORM@"
 config.target_cflags = "@TSAN_TEST_TARGET_CFLAGS@"
 config.target_arch = "@TSAN_TEST_TARGET_ARCH@"
+config.libtirpc_include_dirs = "@Libtirpc_INCLUDE_DIRS@"
 
 # Load common config for all compiler-rt lit tests.
 lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
Index: test/tsan/lit.cfg
===
--- test/tsan/lit.cfg
+++ test/tsan/lit.cfg
@@ -49,7 +49,8 @@
   [config.target_cflags] +
   config.debug_info_flags +
   extra_cflags +
-  ["-I%s" % tsan_incdir])
+  ["-I%s" % tsan_incdir] +
+  [("-I" + x) for x in config.libtirpc_include_dirs])
 clang_tsan_cxxflags = config.cxx_mode_flags + clang_tsan_cflags

[PATCH] D47819: [compiler-rt] [test] Support using libtirpc on Linux

2018-12-23 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179455.
mgorny added a comment.

Fix bug in previous patch.


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

https://reviews.llvm.org/D47819

Files:
  cmake/base-config-ix.cmake
  lib/sanitizer_common/CMakeLists.txt
  test/msan/lit.cfg
  test/msan/lit.site.cfg.in
  test/tsan/lit.cfg
  test/tsan/lit.site.cfg.in


Index: test/tsan/lit.site.cfg.in
===
--- test/tsan/lit.site.cfg.in
+++ test/tsan/lit.site.cfg.in
@@ -6,6 +6,7 @@
 config.apple_platform = "@TSAN_TEST_APPLE_PLATFORM@"
 config.target_cflags = "@TSAN_TEST_TARGET_CFLAGS@"
 config.target_arch = "@TSAN_TEST_TARGET_ARCH@"
+config.libtirpc_include_dirs = "@Libtirpc_INCLUDE_DIRS@"
 
 # Load common config for all compiler-rt lit tests.
 lit_config.load_config(config, 
"@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
Index: test/tsan/lit.cfg
===
--- test/tsan/lit.cfg
+++ test/tsan/lit.cfg
@@ -49,7 +49,8 @@
   [config.target_cflags] +
   config.debug_info_flags +
   extra_cflags +
-  ["-I%s" % tsan_incdir])
+  ["-I%s" % tsan_incdir] +
+  [("-I" + x) for x in 
config.libtirpc_include_dirs.split(';')])
 clang_tsan_cxxflags = config.cxx_mode_flags + clang_tsan_cflags + 
["-std=c++11"] + ["-I%s" % tsan_incdir]
 # Add additional flags if we're using instrumented libc++.
 # Instrumented libcxx currently not supported on Darwin.
Index: test/msan/lit.site.cfg.in
===
--- test/msan/lit.site.cfg.in
+++ test/msan/lit.site.cfg.in
@@ -6,6 +6,7 @@
 config.target_arch = "@MSAN_TEST_TARGET_ARCH@"
 config.use_lld = @MSAN_TEST_USE_LLD@
 config.use_thinlto = @MSAN_TEST_USE_THINLTO@
+config.libtirpc_include_dirs = "@Libtirpc_INCLUDE_DIRS@"
 
 # Load common config for all compiler-rt lit tests.
 lit_config.load_config(config, 
"@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
Index: test/msan/lit.cfg
===
--- test/msan/lit.cfg
+++ test/msan/lit.cfg
@@ -14,7 +14,8 @@
   "-fno-omit-frame-pointer",
   "-fno-optimize-sibling-calls"] +
   [config.target_cflags] +
-  config.debug_info_flags)
+  config.debug_info_flags +
+  [("-I" + x) for x in 
config.libtirpc_include_dirs.split(';')])
 # Some Msan tests leverage backtrace() which requires libexecinfo on FreeBSD.
 if config.host_os == 'FreeBSD':
   clang_msan_cflags += ["-lexecinfo", "-fPIC"]
Index: lib/sanitizer_common/CMakeLists.txt
===
--- lib/sanitizer_common/CMakeLists.txt
+++ lib/sanitizer_common/CMakeLists.txt
@@ -193,8 +193,6 @@
 
 set(SANITIZER_COMMON_DEFINITIONS)
 
-find_package(Libtirpc)
-
 if (Libtirpc_FOUND)
   include_directories(${Libtirpc_INCLUDE_DIRS})
   list(APPEND SANITIZER_COMMON_DEFINITIONS HAVE_RPC_XDR_H=1)
Index: cmake/base-config-ix.cmake
===
--- cmake/base-config-ix.cmake
+++ cmake/base-config-ix.cmake
@@ -8,6 +8,9 @@
 
 check_include_file(unwind.h HAVE_UNWIND_H)
 
+# used in sanitizer_common and tests
+find_package(Libtirpc)
+
 # Top level target used to build all compiler-rt libraries.
 add_custom_target(compiler-rt ALL)
 add_custom_target(install-compiler-rt)


Index: test/tsan/lit.site.cfg.in
===
--- test/tsan/lit.site.cfg.in
+++ test/tsan/lit.site.cfg.in
@@ -6,6 +6,7 @@
 config.apple_platform = "@TSAN_TEST_APPLE_PLATFORM@"
 config.target_cflags = "@TSAN_TEST_TARGET_CFLAGS@"
 config.target_arch = "@TSAN_TEST_TARGET_ARCH@"
+config.libtirpc_include_dirs = "@Libtirpc_INCLUDE_DIRS@"
 
 # Load common config for all compiler-rt lit tests.
 lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
Index: test/tsan/lit.cfg
===
--- test/tsan/lit.cfg
+++ test/tsan/lit.cfg
@@ -49,7 +49,8 @@
   [config.target_cflags] +
   config.debug_info_flags +
   extra_cflags +
-  ["-I%s" % tsan_incdir])
+  ["-I%s" % tsan_incdir] +
+  [("-I" + x) for x in config.libtirpc_include_dirs.split(';')])
 clang_tsan_cxxflags = config.cxx_mode_flags + clang_tsan_cflags + ["-std=c++11"] + ["-I%s" % tsan_incdir]
 # Add additional flags if we're using instrumented libc++.
 # Instrumented libcxx currently not supported on Darwin.
Index: test/msan/lit.site.cfg.in
===
--- test/msan/lit.site.cfg.in
+++ test/msan/lit.site.cfg.in
@@ -6,6 +

[PATCH] D56062: [compiler-rt] [test] Detect glibc-2.27+ and XFAIL appropriate tests

2018-12-23 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: eugenis, kcc, samsonov, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, dberris.

XFAIL the tests known to fail with glibc-2.27+.  This takes away
the burden of handling known failures from users, and ensures that
we will be verbosely informed when they actually start working again.

Bug report: https://bugs.llvm.org/show_bug.cgi?id=37804


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56062

Files:
  test/lit.common.cfg
  test/lsan/TestCases/Linux/use_tls_dynamic.cc
  test/msan/dtls_test.c


Index: test/msan/dtls_test.c
===
--- test/msan/dtls_test.c
+++ test/msan/dtls_test.c
@@ -11,6 +11,11 @@
 
// Reports use-of-uninitialized-value, not analyzed
XFAIL: netbsd
+
+   // This is known to be broken with glibc-2.27+
+   // https://bugs.llvm.org/show_bug.cgi?id=37804
+   // XFAIL: glibc-2.27
+
 */
 
 #ifndef BUILD_SO
Index: test/lsan/TestCases/Linux/use_tls_dynamic.cc
===
--- test/lsan/TestCases/Linux/use_tls_dynamic.cc
+++ test/lsan/TestCases/Linux/use_tls_dynamic.cc
@@ -1,4 +1,9 @@
 // Test that dynamically allocated TLS space is included in the root set.
+
+// This is known to be broken with glibc-2.27+
+// https://bugs.llvm.org/show_bug.cgi?id=37804
+// XFAIL: glibc-2.27
+
 // RUN: 
LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0:use_ld_allocations=0"
 // RUN: %clangxx %s -DBUILD_DSO -fPIC -shared -o %t-so.so
 // RUN: %clangxx_lsan %s -o %t
Index: test/lit.common.cfg
===
--- test/lit.common.cfg
+++ test/lit.common.cfg
@@ -287,6 +287,21 @@
   if android_api_level >= 26:
 config.available_features.add('android-26')
 
+if config.host_os == 'Linux':
+  # detect whether we are using glibc, and which version
+  # NB: 'ldd' is just one of the tools commonly installed as part of glibc
+  ldd_ver_cmd = subprocess.Popen(['ldd', '--version'],
+ stdout=subprocess.PIPE,
+ env={'LANG': 'C'})
+  sout, _ = ldd_ver_cmd.communicate()
+  ver_line = sout.splitlines()[0]
+  if ver_line.startswith(b"ldd "):
+from distutils.version import LooseVersion
+ver = LooseVersion(ver_line.split()[-1].decode())
+# 2.27 introduced some incompatibilities
+if ver >= LooseVersion("2.27"):
+  config.available_features.add("glibc-2.27")
+
 sancovcc_path = os.path.join(config.llvm_tools_dir, "sancov")
 if os.path.exists(sancovcc_path):
   config.available_features.add("has_sancovcc")


Index: test/msan/dtls_test.c
===
--- test/msan/dtls_test.c
+++ test/msan/dtls_test.c
@@ -11,6 +11,11 @@
 
// Reports use-of-uninitialized-value, not analyzed
XFAIL: netbsd
+
+   // This is known to be broken with glibc-2.27+
+   // https://bugs.llvm.org/show_bug.cgi?id=37804
+   // XFAIL: glibc-2.27
+
 */
 
 #ifndef BUILD_SO
Index: test/lsan/TestCases/Linux/use_tls_dynamic.cc
===
--- test/lsan/TestCases/Linux/use_tls_dynamic.cc
+++ test/lsan/TestCases/Linux/use_tls_dynamic.cc
@@ -1,4 +1,9 @@
 // Test that dynamically allocated TLS space is included in the root set.
+
+// This is known to be broken with glibc-2.27+
+// https://bugs.llvm.org/show_bug.cgi?id=37804
+// XFAIL: glibc-2.27
+
 // RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0:use_ld_allocations=0"
 // RUN: %clangxx %s -DBUILD_DSO -fPIC -shared -o %t-so.so
 // RUN: %clangxx_lsan %s -o %t
Index: test/lit.common.cfg
===
--- test/lit.common.cfg
+++ test/lit.common.cfg
@@ -287,6 +287,21 @@
   if android_api_level >= 26:
 config.available_features.add('android-26')
 
+if config.host_os == 'Linux':
+  # detect whether we are using glibc, and which version
+  # NB: 'ldd' is just one of the tools commonly installed as part of glibc
+  ldd_ver_cmd = subprocess.Popen(['ldd', '--version'],
+ stdout=subprocess.PIPE,
+ env={'LANG': 'C'})
+  sout, _ = ldd_ver_cmd.communicate()
+  ver_line = sout.splitlines()[0]
+  if ver_line.startswith(b"ldd "):
+from distutils.version import LooseVersion
+ver = LooseVersion(ver_line.split()[-1].decode())
+# 2.27 introduced some incompatibilities
+if ver >= LooseVersion("2.27"):
+  config.available_features.add("glibc-2.27")
+
 sancovcc_path = os.path.join(config.llvm_tools_dir, "sancov")
 if os.path.exists(sancovcc_path):
   config.available_features.add("has_sancovcc")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47817: [compiler-rt] [sanitizer_common] Fix using libtirpc on Linux

2018-12-24 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179460.
mgorny added a comment.
Herald added subscribers: srhines, emaste.

Updated as requested by @Lekensteyn


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

https://reviews.llvm.org/D47817

Files:
  cmake/Modules/FindLibtirpc.cmake
  lib/sanitizer_common/CMakeLists.txt
  lib/sanitizer_common/sanitizer_platform.h
  lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc
  lib/sanitizer_common/sanitizer_platform_limits_posix.cc

Index: lib/sanitizer_common/sanitizer_platform_limits_posix.cc
===
--- lib/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ lib/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -112,10 +112,8 @@
 #include 
 #include 
 #include 
-#if HAVE_RPC_XDR_H
+#ifdef HAVE_RPC_XDR_H
 # include 
-#elif HAVE_TIRPC_RPC_XDR_H
-# include 
 #endif
 #include 
 #include 
@@ -1210,7 +1208,7 @@
 CHECK_SIZE_AND_OFFSET(group, gr_gid);
 CHECK_SIZE_AND_OFFSET(group, gr_mem);
 
-#if HAVE_RPC_XDR_H || HAVE_TIRPC_RPC_XDR_H
+#ifdef HAVE_RPC_XDR_H
 CHECK_TYPE_SIZE(XDR);
 CHECK_SIZE_AND_OFFSET(XDR, x_op);
 CHECK_SIZE_AND_OFFSET(XDR, x_ops);
Index: lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc
===
--- lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc
+++ lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc
@@ -500,7 +500,7 @@
 CHECK_SIZE_AND_OFFSET(group, gr_gid);
 CHECK_SIZE_AND_OFFSET(group, gr_mem);
 
-#if HAVE_RPC_XDR_H || HAVE_TIRPC_RPC_XDR_H
+#ifdef HAVE_RPC_XDR_H
 CHECK_TYPE_SIZE(XDR);
 CHECK_SIZE_AND_OFFSET(XDR, x_op);
 CHECK_SIZE_AND_OFFSET(XDR, x_ops);
Index: lib/sanitizer_common/sanitizer_platform.h
===
--- lib/sanitizer_common/sanitizer_platform.h
+++ lib/sanitizer_common/sanitizer_platform.h
@@ -275,12 +275,6 @@
 # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 12)
 #endif
 
-// Assume obsolete RPC headers are available by default
-#if !defined(HAVE_RPC_XDR_H) && !defined(HAVE_TIRPC_RPC_XDR_H)
-# define HAVE_RPC_XDR_H (SANITIZER_LINUX && !SANITIZER_ANDROID)
-# define HAVE_TIRPC_RPC_XDR_H 0
-#endif
-
 /// \macro MSC_PREREQ
 /// \brief Is the compiler MSVC of at least the specified version?
 /// The common \param version values to check for are:
Index: lib/sanitizer_common/CMakeLists.txt
===
--- lib/sanitizer_common/CMakeLists.txt
+++ lib/sanitizer_common/CMakeLists.txt
@@ -193,9 +193,12 @@
 
 set(SANITIZER_COMMON_DEFINITIONS)
 
-include(CheckIncludeFile)
-append_have_file_definition(rpc/xdr.h HAVE_RPC_XDR_H SANITIZER_COMMON_DEFINITIONS)
-append_have_file_definition(tirpc/rpc/xdr.h HAVE_TIRPC_RPC_XDR_H SANITIZER_COMMON_DEFINITIONS)
+find_package(Libtirpc)
+
+if (Libtirpc_FOUND)
+  include_directories(${Libtirpc_INCLUDE_DIRS})
+  list(APPEND SANITIZER_COMMON_DEFINITIONS HAVE_RPC_XDR_H=1)
+endif()
 
 set(SANITIZER_CFLAGS ${SANITIZER_COMMON_CFLAGS})
 append_rtti_flag(OFF SANITIZER_CFLAGS)
Index: cmake/Modules/FindLibtirpc.cmake
===
--- /dev/null
+++ cmake/Modules/FindLibtirpc.cmake
@@ -0,0 +1,22 @@
+# CMake find_package() Module for libtirpc
+#
+# Example usage:
+#
+# find_package(Libtirpc)
+#
+# If successful the following variables will be defined
+# Libtirpc_FOUND
+# Libtirpc_INCLUDE_DIRS
+
+find_path(Libtirpc_INCLUDE_DIR
+  NAMES rpc/xdr.h
+  PATH_SUFFIXES tirpc
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Libtirpc
+	REQUIRED_VARS Libtirpc_INCLUDE_DIR)
+
+if(Libtirpc_FOUND)
+  set(Libtirpc_INCLUDE_DIRS ${Libtirpc_INCLUDE_DIR})
+endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47817: [compiler-rt] [sanitizer_common] Remove support for tirpc/rpc/xdr.h

2018-12-27 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179556.
mgorny retitled this revision from "[compiler-rt] [sanitizer_common] Fix using 
libtirpc on Linux" to "[compiler-rt] [sanitizer_common] Remove support for 
tirpc/rpc/xdr.h".
mgorny edited the summary of this revision.
mgorny added reviewers: krytarowski, vitalybuka.
mgorny added a comment.

Updated to remove tirpc support completely instead, as suggested by 
@krytarowski. Now only built-in glibc implementation is intercepted, and the 
external tirpc library is left for being built with `-fsanitize`.


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

https://reviews.llvm.org/D47817

Files:
  lib/sanitizer_common/CMakeLists.txt
  lib/sanitizer_common/sanitizer_platform.h
  lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc
  lib/sanitizer_common/sanitizer_platform_limits_posix.cc


Index: lib/sanitizer_common/sanitizer_platform_limits_posix.cc
===
--- lib/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ lib/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -114,8 +114,6 @@
 #include 
 #if HAVE_RPC_XDR_H
 # include 
-#elif HAVE_TIRPC_RPC_XDR_H
-# include 
 #endif
 #include 
 #include 
@@ -1210,7 +1208,7 @@
 CHECK_SIZE_AND_OFFSET(group, gr_gid);
 CHECK_SIZE_AND_OFFSET(group, gr_mem);
 
-#if HAVE_RPC_XDR_H || HAVE_TIRPC_RPC_XDR_H
+#if HAVE_RPC_XDR_H
 CHECK_TYPE_SIZE(XDR);
 CHECK_SIZE_AND_OFFSET(XDR, x_op);
 CHECK_SIZE_AND_OFFSET(XDR, x_ops);
Index: lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc
===
--- lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc
+++ lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc
@@ -500,7 +500,7 @@
 CHECK_SIZE_AND_OFFSET(group, gr_gid);
 CHECK_SIZE_AND_OFFSET(group, gr_mem);
 
-#if HAVE_RPC_XDR_H || HAVE_TIRPC_RPC_XDR_H
+#if HAVE_RPC_XDR_H
 CHECK_TYPE_SIZE(XDR);
 CHECK_SIZE_AND_OFFSET(XDR, x_op);
 CHECK_SIZE_AND_OFFSET(XDR, x_ops);
Index: lib/sanitizer_common/sanitizer_platform.h
===
--- lib/sanitizer_common/sanitizer_platform.h
+++ lib/sanitizer_common/sanitizer_platform.h
@@ -275,12 +275,6 @@
 # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 12)
 #endif
 
-// Assume obsolete RPC headers are available by default
-#if !defined(HAVE_RPC_XDR_H) && !defined(HAVE_TIRPC_RPC_XDR_H)
-# define HAVE_RPC_XDR_H (SANITIZER_LINUX && !SANITIZER_ANDROID)
-# define HAVE_TIRPC_RPC_XDR_H 0
-#endif
-
 /// \macro MSC_PREREQ
 /// \brief Is the compiler MSVC of at least the specified version?
 /// The common \param version values to check for are:
Index: lib/sanitizer_common/CMakeLists.txt
===
--- lib/sanitizer_common/CMakeLists.txt
+++ lib/sanitizer_common/CMakeLists.txt
@@ -195,7 +195,6 @@
 
 include(CheckIncludeFile)
 append_have_file_definition(rpc/xdr.h HAVE_RPC_XDR_H 
SANITIZER_COMMON_DEFINITIONS)
-append_have_file_definition(tirpc/rpc/xdr.h HAVE_TIRPC_RPC_XDR_H 
SANITIZER_COMMON_DEFINITIONS)
 
 set(SANITIZER_CFLAGS ${SANITIZER_COMMON_CFLAGS})
 append_rtti_flag(OFF SANITIZER_CFLAGS)


Index: lib/sanitizer_common/sanitizer_platform_limits_posix.cc
===
--- lib/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ lib/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -114,8 +114,6 @@
 #include 
 #if HAVE_RPC_XDR_H
 # include 
-#elif HAVE_TIRPC_RPC_XDR_H
-# include 
 #endif
 #include 
 #include 
@@ -1210,7 +1208,7 @@
 CHECK_SIZE_AND_OFFSET(group, gr_gid);
 CHECK_SIZE_AND_OFFSET(group, gr_mem);
 
-#if HAVE_RPC_XDR_H || HAVE_TIRPC_RPC_XDR_H
+#if HAVE_RPC_XDR_H
 CHECK_TYPE_SIZE(XDR);
 CHECK_SIZE_AND_OFFSET(XDR, x_op);
 CHECK_SIZE_AND_OFFSET(XDR, x_ops);
Index: lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc
===
--- lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc
+++ lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc
@@ -500,7 +500,7 @@
 CHECK_SIZE_AND_OFFSET(group, gr_gid);
 CHECK_SIZE_AND_OFFSET(group, gr_mem);
 
-#if HAVE_RPC_XDR_H || HAVE_TIRPC_RPC_XDR_H
+#if HAVE_RPC_XDR_H
 CHECK_TYPE_SIZE(XDR);
 CHECK_SIZE_AND_OFFSET(XDR, x_op);
 CHECK_SIZE_AND_OFFSET(XDR, x_ops);
Index: lib/sanitizer_common/sanitizer_platform.h
===
--- lib/sanitizer_common/sanitizer_platform.h
+++ lib/sanitizer_common/sanitizer_platform.h
@@ -275,12 +275,6 @@
 # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 12)
 #endif
 
-// Assume obsolete RPC headers are available by default
-#if !defined(HAVE_RPC_XDR_H) && !defined(HAVE_TIRPC_RPC_XDR_H)
-# define HAVE_RPC_XDR_H (SANITIZER_LINUX && !SANITIZER_ANDROID)
-# define HAVE_TIRPC_RPC_XDR_H 0
-#endif
-
 /// \macro MSC_PREREQ
 /// \brief Is the compiler MSVC of at least the specified ve

[PATCH] D56109: [sanitizer_common] Define __sanitizer_FILE on NetBSD

2018-12-27 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek.

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56109

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
  lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
  lib/tsan/rtl/tsan_interceptors.cc

Index: lib/tsan/rtl/tsan_interceptors.cc
===
--- lib/tsan/rtl/tsan_interceptors.cc
+++ lib/tsan/rtl/tsan_interceptors.cc
@@ -44,14 +44,8 @@
 #define dirfd(dirp) (*(int *)(dirp))
 #define fileno_unlocked fileno
 
-#if _LP64
-#define __sF_size 152
-#else
-#define __sF_size 88
-#endif
-
-#define stdout ((char*)&__sF + (__sF_size * 1))
-#define stderr ((char*)&__sF + (__sF_size * 2))
+#define stdout ((__sanitizer_FILE*)&__sF[1])
+#define stderr ((__sanitizer_FILE*)&__sF[2])
 
 #define nanosleep __nanosleep50
 #define vfork __vfork14
Index: lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
===
--- lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
+++ lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
@@ -446,8 +446,36 @@
   uptr we_nbytes;
 };
 
-typedef char __sanitizer_FILE;
-#define SANITIZER_HAS_STRUCT_FILE 0
+struct __sanitizer_FILE {
+  unsigned char *_p;
+  int _r;
+  int _w;
+  unsigned short _flags;
+  short _file;
+  struct {
+unsigned char *_base;
+int _size;
+  } _bf;
+  int _lbfsize;
+  void *_cookie;
+  int (*_close)(void *ptr);
+  u64 (*_read)(void *, void *, uptr);
+  u64 (*_seek)(void *, u64, int);
+  uptr (*_write)(void *, const void *, uptr);
+  struct {
+unsigned char *_base;
+int _size;
+  } _ext;
+  unsigned char *_up;
+  int _ur;
+  unsigned char _ubuf[3];
+  unsigned char _nbuf[1];
+  int (*_flush)(void *ptr);
+  char _lb_unused[sizeof(uptr)];
+  int _blksize;
+  u64 _offset;
+};
+#define SANITIZER_HAS_STRUCT_FILE 1
 
 extern int shmctl_ipc_stat;
 
Index: lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
===
--- lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
+++ lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
@@ -2224,6 +2224,30 @@
 CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordv);
 CHECK_SIZE_AND_OFFSET(wordexp_t, we_offs);
 
+COMPILER_CHECK(sizeof(__sanitizer_FILE) <= sizeof(FILE));
+CHECK_SIZE_AND_OFFSET(FILE, _p);
+CHECK_SIZE_AND_OFFSET(FILE, _r);
+CHECK_SIZE_AND_OFFSET(FILE, _w);
+CHECK_SIZE_AND_OFFSET(FILE, _flags);
+CHECK_SIZE_AND_OFFSET(FILE, _file);
+CHECK_SIZE_AND_OFFSET(FILE, _bf);
+CHECK_SIZE_AND_OFFSET(FILE, _lbfsize);
+CHECK_SIZE_AND_OFFSET(FILE, _cookie);
+CHECK_SIZE_AND_OFFSET(FILE, _close);
+CHECK_SIZE_AND_OFFSET(FILE, _read);
+CHECK_SIZE_AND_OFFSET(FILE, _seek);
+CHECK_SIZE_AND_OFFSET(FILE, _write);
+CHECK_SIZE_AND_OFFSET(FILE, _ext);
+CHECK_SIZE_AND_OFFSET(FILE, _up);
+CHECK_SIZE_AND_OFFSET(FILE, _ur);
+CHECK_SIZE_AND_OFFSET(FILE, _ubuf);
+CHECK_SIZE_AND_OFFSET(FILE, _nbuf);
+CHECK_SIZE_AND_OFFSET(FILE, _flush);
+CHECK_SIZE_AND_OFFSET(FILE, _lb_unused);
+CHECK_SIZE_AND_OFFSET(FILE, _blksize);
+CHECK_SIZE_AND_OFFSET(FILE, _offset);
+CHECK_SIZE_AND_OFFSET(FILE, _flags);
+
 CHECK_TYPE_SIZE(tm);
 CHECK_SIZE_AND_OFFSET(tm, tm_sec);
 CHECK_SIZE_AND_OFFSET(tm, tm_min);
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -5694,9 +5694,15 @@
 void unpoison_file(__sanitizer_FILE *fp) {
 #if SANITIZER_HAS_STRUCT_FILE
   COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp, sizeof(*fp));
+#if SANITIZER_NETBSD
+  if (fp->_bf._base)
+COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp->_bf._base,
+fp->_bf._size);
+#else
   if (fp->_IO_read_base && fp->_IO_read_base < fp->_IO_read_end)
 COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp->_IO_read_base,
 fp->_IO_read_end - fp->_IO_read_base);
+#endif
 #endif  // SANITIZER_HAS_STRUCT_FILE
 }
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56109: [sanitizer_common] Define __sanitizer_FILE on NetBSD

2018-12-27 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179570.
mgorny marked 2 inline comments as done.

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

https://reviews.llvm.org/D56109

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
  lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
  lib/tsan/rtl/tsan_interceptors.cc

Index: lib/tsan/rtl/tsan_interceptors.cc
===
--- lib/tsan/rtl/tsan_interceptors.cc
+++ lib/tsan/rtl/tsan_interceptors.cc
@@ -44,14 +44,8 @@
 #define dirfd(dirp) (*(int *)(dirp))
 #define fileno_unlocked fileno
 
-#if _LP64
-#define __sF_size 152
-#else
-#define __sF_size 88
-#endif
-
-#define stdout ((char*)&__sF + (__sF_size * 1))
-#define stderr ((char*)&__sF + (__sF_size * 2))
+#define stdout ((__sanitizer_FILE*)&__sF[1])
+#define stderr ((__sanitizer_FILE*)&__sF[2])
 
 #define nanosleep __nanosleep50
 #define vfork __vfork14
Index: lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
===
--- lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
+++ lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
@@ -446,8 +446,36 @@
   uptr we_nbytes;
 };
 
-typedef char __sanitizer_FILE;
-#define SANITIZER_HAS_STRUCT_FILE 0
+struct __sanitizer_FILE {
+  unsigned char *_p;
+  int _r;
+  int _w;
+  unsigned short _flags;
+  short _file;
+  struct {
+unsigned char *_base;
+int _size;
+  } _bf;
+  int _lbfsize;
+  void *_cookie;
+  int (*_close)(void *ptr);
+  u64 (*_read)(void *, void *, uptr);
+  u64 (*_seek)(void *, u64, int);
+  uptr (*_write)(void *, const void *, uptr);
+  struct {
+unsigned char *_base;
+int _size;
+  } _ext;
+  unsigned char *_up;
+  int _ur;
+  unsigned char _ubuf[3];
+  unsigned char _nbuf[1];
+  int (*_flush)(void *ptr);
+  char _lb_unused[sizeof(uptr)];
+  int _blksize;
+  u64 _offset;
+};
+#define SANITIZER_HAS_STRUCT_FILE 1
 
 extern int shmctl_ipc_stat;
 
Index: lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
===
--- lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
+++ lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
@@ -2224,6 +2224,29 @@
 CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordv);
 CHECK_SIZE_AND_OFFSET(wordexp_t, we_offs);
 
+COMPILER_CHECK(sizeof(__sanitizer_FILE) <= sizeof(FILE));
+CHECK_SIZE_AND_OFFSET(FILE, _p);
+CHECK_SIZE_AND_OFFSET(FILE, _r);
+CHECK_SIZE_AND_OFFSET(FILE, _w);
+CHECK_SIZE_AND_OFFSET(FILE, _flags);
+CHECK_SIZE_AND_OFFSET(FILE, _file);
+CHECK_SIZE_AND_OFFSET(FILE, _bf);
+CHECK_SIZE_AND_OFFSET(FILE, _lbfsize);
+CHECK_SIZE_AND_OFFSET(FILE, _cookie);
+CHECK_SIZE_AND_OFFSET(FILE, _close);
+CHECK_SIZE_AND_OFFSET(FILE, _read);
+CHECK_SIZE_AND_OFFSET(FILE, _seek);
+CHECK_SIZE_AND_OFFSET(FILE, _write);
+CHECK_SIZE_AND_OFFSET(FILE, _ext);
+CHECK_SIZE_AND_OFFSET(FILE, _up);
+CHECK_SIZE_AND_OFFSET(FILE, _ur);
+CHECK_SIZE_AND_OFFSET(FILE, _ubuf);
+CHECK_SIZE_AND_OFFSET(FILE, _nbuf);
+CHECK_SIZE_AND_OFFSET(FILE, _flush);
+CHECK_SIZE_AND_OFFSET(FILE, _lb_unused);
+CHECK_SIZE_AND_OFFSET(FILE, _blksize);
+CHECK_SIZE_AND_OFFSET(FILE, _offset);
+
 CHECK_TYPE_SIZE(tm);
 CHECK_SIZE_AND_OFFSET(tm, tm_sec);
 CHECK_SIZE_AND_OFFSET(tm, tm_min);
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -5694,9 +5694,15 @@
 void unpoison_file(__sanitizer_FILE *fp) {
 #if SANITIZER_HAS_STRUCT_FILE
   COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp, sizeof(*fp));
+#if SANITIZER_NETBSD
+  if (fp->_bf._base)
+COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp->_bf._base,
+fp->_bf._size);
+#else
   if (fp->_IO_read_base && fp->_IO_read_base < fp->_IO_read_end)
 COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp->_IO_read_base,
 fp->_IO_read_end - fp->_IO_read_base);
+#endif
 #endif  // SANITIZER_HAS_STRUCT_FILE
 }
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56109: [sanitizer_common] Define __sanitizer_FILE on NetBSD

2018-12-27 Thread Michał Górny via Phabricator via cfe-commits
mgorny added inline comments.



Comment at: lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc:2249
+CHECK_SIZE_AND_OFFSET(FILE, _offset);
+CHECK_SIZE_AND_OFFSET(FILE, _flags);
+

krytarowski wrote:
> Duplicate with L2231
Fixed.


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

https://reviews.llvm.org/D56109



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56109: [sanitizer_common] Define __sanitizer_FILE on NetBSD

2018-12-28 Thread Michał Górny via Phabricator via cfe-commits
mgorny marked 2 inline comments as done.
mgorny added inline comments.



Comment at: lib/sanitizer_common/sanitizer_common_interceptors.inc:5698
+#if SANITIZER_NETBSD
+  if (fp->_bf._base)
+COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp->_bf._base,

krytarowski wrote:
> maybe `if (fp->_bf._base && fp->_bf._size)`
Ok. I'll even take it further, and since `_size` is signed, check for `> 0`.


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

https://reviews.llvm.org/D56109



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56109: [sanitizer_common] Define __sanitizer_FILE on NetBSD

2018-12-28 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179641.
mgorny marked an inline comment as done.

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

https://reviews.llvm.org/D56109

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
  lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
  lib/tsan/rtl/tsan_interceptors.cc

Index: lib/tsan/rtl/tsan_interceptors.cc
===
--- lib/tsan/rtl/tsan_interceptors.cc
+++ lib/tsan/rtl/tsan_interceptors.cc
@@ -44,14 +44,8 @@
 #define dirfd(dirp) (*(int *)(dirp))
 #define fileno_unlocked fileno
 
-#if _LP64
-#define __sF_size 152
-#else
-#define __sF_size 88
-#endif
-
-#define stdout ((char*)&__sF + (__sF_size * 1))
-#define stderr ((char*)&__sF + (__sF_size * 2))
+#define stdout ((__sanitizer_FILE*)&__sF[1])
+#define stderr ((__sanitizer_FILE*)&__sF[2])
 
 #define nanosleep __nanosleep50
 #define vfork __vfork14
Index: lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
===
--- lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
+++ lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
@@ -446,8 +446,36 @@
   uptr we_nbytes;
 };
 
-typedef char __sanitizer_FILE;
-#define SANITIZER_HAS_STRUCT_FILE 0
+struct __sanitizer_FILE {
+  unsigned char *_p;
+  int _r;
+  int _w;
+  unsigned short _flags;
+  short _file;
+  struct {
+unsigned char *_base;
+int _size;
+  } _bf;
+  int _lbfsize;
+  void *_cookie;
+  int (*_close)(void *ptr);
+  u64 (*_read)(void *, void *, uptr);
+  u64 (*_seek)(void *, u64, int);
+  uptr (*_write)(void *, const void *, uptr);
+  struct {
+unsigned char *_base;
+int _size;
+  } _ext;
+  unsigned char *_up;
+  int _ur;
+  unsigned char _ubuf[3];
+  unsigned char _nbuf[1];
+  int (*_flush)(void *ptr);
+  char _lb_unused[sizeof(uptr)];
+  int _blksize;
+  u64 _offset;
+};
+#define SANITIZER_HAS_STRUCT_FILE 1
 
 extern int shmctl_ipc_stat;
 
Index: lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
===
--- lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
+++ lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
@@ -2224,6 +2224,29 @@
 CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordv);
 CHECK_SIZE_AND_OFFSET(wordexp_t, we_offs);
 
+COMPILER_CHECK(sizeof(__sanitizer_FILE) <= sizeof(FILE));
+CHECK_SIZE_AND_OFFSET(FILE, _p);
+CHECK_SIZE_AND_OFFSET(FILE, _r);
+CHECK_SIZE_AND_OFFSET(FILE, _w);
+CHECK_SIZE_AND_OFFSET(FILE, _flags);
+CHECK_SIZE_AND_OFFSET(FILE, _file);
+CHECK_SIZE_AND_OFFSET(FILE, _bf);
+CHECK_SIZE_AND_OFFSET(FILE, _lbfsize);
+CHECK_SIZE_AND_OFFSET(FILE, _cookie);
+CHECK_SIZE_AND_OFFSET(FILE, _close);
+CHECK_SIZE_AND_OFFSET(FILE, _read);
+CHECK_SIZE_AND_OFFSET(FILE, _seek);
+CHECK_SIZE_AND_OFFSET(FILE, _write);
+CHECK_SIZE_AND_OFFSET(FILE, _ext);
+CHECK_SIZE_AND_OFFSET(FILE, _up);
+CHECK_SIZE_AND_OFFSET(FILE, _ur);
+CHECK_SIZE_AND_OFFSET(FILE, _ubuf);
+CHECK_SIZE_AND_OFFSET(FILE, _nbuf);
+CHECK_SIZE_AND_OFFSET(FILE, _flush);
+CHECK_SIZE_AND_OFFSET(FILE, _lb_unused);
+CHECK_SIZE_AND_OFFSET(FILE, _blksize);
+CHECK_SIZE_AND_OFFSET(FILE, _offset);
+
 CHECK_TYPE_SIZE(tm);
 CHECK_SIZE_AND_OFFSET(tm, tm_sec);
 CHECK_SIZE_AND_OFFSET(tm, tm_min);
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -5694,9 +5694,15 @@
 void unpoison_file(__sanitizer_FILE *fp) {
 #if SANITIZER_HAS_STRUCT_FILE
   COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp, sizeof(*fp));
+#if SANITIZER_NETBSD
+  if (fp->_bf._base && fp->_bf._size > 0)
+COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp->_bf._base,
+fp->_bf._size);
+#else
   if (fp->_IO_read_base && fp->_IO_read_base < fp->_IO_read_end)
 COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp->_IO_read_base,
 fp->_IO_read_end - fp->_IO_read_base);
+#endif
 #endif  // SANITIZER_HAS_STRUCT_FILE
 }
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56109: [sanitizer_common] Define __sanitizer_FILE on NetBSD

2018-12-28 Thread Michał Górny via Phabricator via cfe-commits
mgorny added reviewers: eugenis, kcc.
mgorny added a comment.

We've been discussing this, and I think we're doing this the wrong way. Could 
you help me a little understand this?

In particular, what is the purpose of unpoisoning file? Is it in order to 
account for stdio functions being implemented inline or as macros, and 
therefore user code accessing internal `FILE` members? Or is there some other 
use case for this?

If only the former, then I think there is no purpose in definining 
`__sanitizer_FILE` on NetBSD, as we support only reentrant interfaces which are 
all implemented as libc routine calls.


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

https://reviews.llvm.org/D56109



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56136: [compiler-rt] [sanitizer_common] Add tests for more stdio.h functions

2018-12-28 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, dberris, kubamracek.

Add two new test cases that test the following stdio.h functions:

- clearerr()
- feof()
- ferror()
- fileno()
- fgetc()
- getc()
- ungetc()


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56136

Files:
  test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
  test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc


Index: test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
@@ -0,0 +1,23 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp;
+
+  fp = fopen(argv[0], "r");
+  if (!fp)
+return 1;
+
+  if (fgetc(fp) == EOF)
+return 2;
+
+  if (ungetc('X', fp) == EOF)
+return 3;
+
+  if (getc(fp) != 'X')
+return 4;
+
+  fclose(fp);
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
@@ -0,0 +1,51 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp;
+  int fd;
+  char buf[BUFSIZ];
+
+  fp = fopen(argv[0], "r");
+  if (!fp)
+return 1;
+
+  // file should be good upon opening
+  if (feof(fp) || ferror(fp))
+return 2;
+
+  // read until EOF
+  while (fread(buf, 1, sizeof buf, fp) != 0) {}
+  if (!feof(fp))
+return 3;
+
+  // clear EOF
+  clearerr(fp);
+  if (feof(fp) || ferror(fp))
+return 4;
+
+  // get file descriptor
+  fd = fileno(fp);
+  if (fd == -1)
+return 5;
+
+  // break the file by closing underlying descriptor
+  if (close(fd) == -1)
+return 6;
+
+  // verify that an error is signalled
+  if (fread(buf, 1, sizeof buf, fp) != 0)
+return 7;
+  if (!ferror(fp))
+return 8;
+
+  // clear error
+  clearerr(fp);
+  if (feof(fp) || ferror(fp))
+return 9;
+
+  fclose(fp);
+  return 0;
+}


Index: test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
@@ -0,0 +1,23 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp;
+
+  fp = fopen(argv[0], "r");
+  if (!fp)
+return 1;
+
+  if (fgetc(fp) == EOF)
+return 2;
+
+  if (ungetc('X', fp) == EOF)
+return 3;
+
+  if (getc(fp) != 'X')
+return 4;
+
+  fclose(fp);
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
@@ -0,0 +1,51 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp;
+  int fd;
+  char buf[BUFSIZ];
+
+  fp = fopen(argv[0], "r");
+  if (!fp)
+return 1;
+
+  // file should be good upon opening
+  if (feof(fp) || ferror(fp))
+return 2;
+
+  // read until EOF
+  while (fread(buf, 1, sizeof buf, fp) != 0) {}
+  if (!feof(fp))
+return 3;
+
+  // clear EOF
+  clearerr(fp);
+  if (feof(fp) || ferror(fp))
+return 4;
+
+  // get file descriptor
+  fd = fileno(fp);
+  if (fd == -1)
+return 5;
+
+  // break the file by closing underlying descriptor
+  if (close(fd) == -1)
+return 6;
+
+  // verify that an error is signalled
+  if (fread(buf, 1, sizeof buf, fp) != 0)
+return 7;
+  if (!ferror(fp))
+return 8;
+
+  // clear error
+  clearerr(fp);
+  if (feof(fp) || ferror(fp))
+return 9;
+
+  fclose(fp);
+  return 0;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56136: [compiler-rt] [sanitizer_common] Add tests for more stdio.h functions

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny marked 4 inline comments as done.
mgorny added inline comments.



Comment at: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc:49
+
+  fclose(fp);
+  return 0;

vitalybuka wrote:
> why does this close file only on success?
> I assume normal test behavior is return 0;
> So please replace all return N with  asserts so when it fail we will have 
> verbose output
> e.g
> ```
> assert(close(fd) != -1);
> 
> assert(ferror(fp));
> ```
> 
Will do. I've copied this from `fgets.cc`, `fputs_puts.cc` tests, and wrongly 
presumed it's expected coding style.


Repository:
  rCRT Compiler Runtime

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

https://reviews.llvm.org/D56136



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56136: [compiler-rt] [sanitizer_common] Add tests for more stdio.h functions

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179679.
mgorny marked an inline comment as done.
mgorny added a comment.

Moved variable definitions, and added asserts.


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

https://reviews.llvm.org/D56136

Files:
  test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
  test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc


Index: test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
@@ -0,0 +1,19 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(fgetc(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() worked
+  assert(getc(fp) == 'X');
+
+  fclose(fp);
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
@@ -0,0 +1,40 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // file should be good upon opening
+  assert(!feof(fp) && !ferror(fp));
+
+  // read until EOF
+  char buf[BUFSIZ];
+  while (fread(buf, 1, sizeof buf, fp) != 0) {}
+  assert(feof(fp));
+
+  // clear EOF
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  // get file descriptor
+  int fd = fileno(fp);
+  assert(fd != -1);
+
+  // break the file by closing underlying descriptor
+  assert(close(fd) != -1);
+
+  // verify that an error is signalled
+  assert(fread(buf, 1, sizeof buf, fp) == 0);
+  assert(ferror(fp));
+
+  // clear error
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  fclose(fp);
+  return 0;
+}


Index: test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
@@ -0,0 +1,19 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(fgetc(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() worked
+  assert(getc(fp) == 'X');
+
+  fclose(fp);
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
@@ -0,0 +1,40 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // file should be good upon opening
+  assert(!feof(fp) && !ferror(fp));
+
+  // read until EOF
+  char buf[BUFSIZ];
+  while (fread(buf, 1, sizeof buf, fp) != 0) {}
+  assert(feof(fp));
+
+  // clear EOF
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  // get file descriptor
+  int fd = fileno(fp);
+  assert(fd != -1);
+
+  // break the file by closing underlying descriptor
+  assert(close(fd) != -1);
+
+  // verify that an error is signalled
+  assert(fread(buf, 1, sizeof buf, fp) == 0);
+  assert(ferror(fp));
+
+  // clear error
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  fclose(fp);
+  return 0;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56109: [sanitizer_common] Define __sanitizer_FILE on NetBSD

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179681.
mgorny added a comment.

Implemented `fileno_unlocked` as requested.


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

https://reviews.llvm.org/D56109

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
  lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
  lib/tsan/rtl/tsan_interceptors.cc

Index: lib/tsan/rtl/tsan_interceptors.cc
===
--- lib/tsan/rtl/tsan_interceptors.cc
+++ lib/tsan/rtl/tsan_interceptors.cc
@@ -42,16 +42,12 @@
 
 #if SANITIZER_NETBSD
 #define dirfd(dirp) (*(int *)(dirp))
-#define fileno_unlocked fileno
+#define fileno_unlocked(fp) \
+  (((__sanitizer_FILE*)fp)->_file == -1 ? -1 : \
+   (int)(unsigned short)(((__sanitizer_FILE*)fp)->_file))  // NOLINT
 
-#if _LP64
-#define __sF_size 152
-#else
-#define __sF_size 88
-#endif
-
-#define stdout ((char*)&__sF + (__sF_size * 1))
-#define stderr ((char*)&__sF + (__sF_size * 2))
+#define stdout ((__sanitizer_FILE*)&__sF[1])
+#define stderr ((__sanitizer_FILE*)&__sF[2])
 
 #define nanosleep __nanosleep50
 #define vfork __vfork14
@@ -96,8 +92,8 @@
 DECLARE_REAL_AND_INTERCEPTOR(void, free, void *ptr)
 extern "C" void *pthread_self();
 extern "C" void _exit(int status);
-extern "C" int fileno_unlocked(void *stream);
 #if !SANITIZER_NETBSD
+extern "C" int fileno_unlocked(void *stream);
 extern "C" int dirfd(void *dirp);
 #endif
 #if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_NETBSD
Index: lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
===
--- lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
+++ lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
@@ -446,8 +446,36 @@
   uptr we_nbytes;
 };
 
-typedef char __sanitizer_FILE;
-#define SANITIZER_HAS_STRUCT_FILE 0
+struct __sanitizer_FILE {
+  unsigned char *_p;
+  int _r;
+  int _w;
+  unsigned short _flags;
+  short _file;
+  struct {
+unsigned char *_base;
+int _size;
+  } _bf;
+  int _lbfsize;
+  void *_cookie;
+  int (*_close)(void *ptr);
+  u64 (*_read)(void *, void *, uptr);
+  u64 (*_seek)(void *, u64, int);
+  uptr (*_write)(void *, const void *, uptr);
+  struct {
+unsigned char *_base;
+int _size;
+  } _ext;
+  unsigned char *_up;
+  int _ur;
+  unsigned char _ubuf[3];
+  unsigned char _nbuf[1];
+  int (*_flush)(void *ptr);
+  char _lb_unused[sizeof(uptr)];
+  int _blksize;
+  u64 _offset;
+};
+#define SANITIZER_HAS_STRUCT_FILE 1
 
 extern int shmctl_ipc_stat;
 
Index: lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
===
--- lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
+++ lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
@@ -2224,6 +2224,29 @@
 CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordv);
 CHECK_SIZE_AND_OFFSET(wordexp_t, we_offs);
 
+COMPILER_CHECK(sizeof(__sanitizer_FILE) <= sizeof(FILE));
+CHECK_SIZE_AND_OFFSET(FILE, _p);
+CHECK_SIZE_AND_OFFSET(FILE, _r);
+CHECK_SIZE_AND_OFFSET(FILE, _w);
+CHECK_SIZE_AND_OFFSET(FILE, _flags);
+CHECK_SIZE_AND_OFFSET(FILE, _file);
+CHECK_SIZE_AND_OFFSET(FILE, _bf);
+CHECK_SIZE_AND_OFFSET(FILE, _lbfsize);
+CHECK_SIZE_AND_OFFSET(FILE, _cookie);
+CHECK_SIZE_AND_OFFSET(FILE, _close);
+CHECK_SIZE_AND_OFFSET(FILE, _read);
+CHECK_SIZE_AND_OFFSET(FILE, _seek);
+CHECK_SIZE_AND_OFFSET(FILE, _write);
+CHECK_SIZE_AND_OFFSET(FILE, _ext);
+CHECK_SIZE_AND_OFFSET(FILE, _up);
+CHECK_SIZE_AND_OFFSET(FILE, _ur);
+CHECK_SIZE_AND_OFFSET(FILE, _ubuf);
+CHECK_SIZE_AND_OFFSET(FILE, _nbuf);
+CHECK_SIZE_AND_OFFSET(FILE, _flush);
+CHECK_SIZE_AND_OFFSET(FILE, _lb_unused);
+CHECK_SIZE_AND_OFFSET(FILE, _blksize);
+CHECK_SIZE_AND_OFFSET(FILE, _offset);
+
 CHECK_TYPE_SIZE(tm);
 CHECK_SIZE_AND_OFFSET(tm, tm_sec);
 CHECK_SIZE_AND_OFFSET(tm, tm_min);
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -5694,9 +5694,15 @@
 void unpoison_file(__sanitizer_FILE *fp) {
 #if SANITIZER_HAS_STRUCT_FILE
   COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp, sizeof(*fp));
+#if SANITIZER_NETBSD
+  if (fp->_bf._base && fp->_bf._size > 0)
+COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp->_bf._base,
+fp->_bf._size);
+#else
   if (fp->_IO_read_base && fp->_IO_read_base < fp->_IO_read_end)
 COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp->_IO_read_base,
 fp->_IO_read_end - fp->_IO_read_base);
+#endif
 #endif  // SANITIZER_HAS_STRUCT_FILE
 }
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56136: [compiler-rt] [sanitizer_common] Add tests for more stdio.h functions

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny added inline comments.



Comment at: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc:38
+
+  fclose(fp);
+  return 0;

krytarowski wrote:
> krytarowski wrote:
> > `assert(!fclose(fp));`
> alternatively `!= EOF`
It will fail most likely, due to us closing the fd before. However, I'm not 
sure if we want to strictly rely on this error condition.


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

https://reviews.llvm.org/D56136



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56136: [compiler-rt] [sanitizer_common] Add tests for more stdio.h functions

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

(Do you have another idea how to reliably trigger `ferror`?)


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

https://reviews.llvm.org/D56136



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56136: [compiler-rt] [sanitizer_common] Add tests for more stdio.h functions

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179691.
mgorny added a comment.

Added asserts for `fclose()`.


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

https://reviews.llvm.org/D56136

Files:
  test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
  test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc


Index: test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
@@ -0,0 +1,19 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(fgetc(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() worked
+  assert(getc(fp) == 'X');
+
+  assert(!fclose(fp));
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
@@ -0,0 +1,41 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // file should be good upon opening
+  assert(!feof(fp) && !ferror(fp));
+
+  // read until EOF
+  char buf[BUFSIZ];
+  while (fread(buf, 1, sizeof buf, fp) != 0) {}
+  assert(feof(fp));
+
+  // clear EOF
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  // get file descriptor
+  int fd = fileno(fp);
+  assert(fd != -1);
+
+  // break the file by closing underlying descriptor
+  assert(close(fd) != -1);
+
+  // verify that an error is signalled
+  assert(fread(buf, 1, sizeof buf, fp) == 0);
+  assert(ferror(fp));
+
+  // clear error
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  // fclose() will return EBADF because of closed fd
+  assert(fclose(fp) == -1);
+  return 0;
+}


Index: test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
@@ -0,0 +1,19 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(fgetc(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() worked
+  assert(getc(fp) == 'X');
+
+  assert(!fclose(fp));
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
@@ -0,0 +1,41 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // file should be good upon opening
+  assert(!feof(fp) && !ferror(fp));
+
+  // read until EOF
+  char buf[BUFSIZ];
+  while (fread(buf, 1, sizeof buf, fp) != 0) {}
+  assert(feof(fp));
+
+  // clear EOF
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  // get file descriptor
+  int fd = fileno(fp);
+  assert(fd != -1);
+
+  // break the file by closing underlying descriptor
+  assert(close(fd) != -1);
+
+  // verify that an error is signalled
+  assert(fread(buf, 1, sizeof buf, fp) == 0);
+  assert(ferror(fp));
+
+  // clear error
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  // fclose() will return EBADF because of closed fd
+  assert(fclose(fp) == -1);
+  return 0;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56149: [sanitizer_common] Rewrite fgets/fputs/puts tests to use asserts

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek.

Rewrite the tests for fgets and for fputs/puts to verify results
using assert instead of silently returning non-zero exit status.
This is based on requests made in review of D56136 
.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56149

Files:
  test/sanitizer_common/TestCases/Posix/fgets.cc
  test/sanitizer_common/TestCases/Posix/fputs_puts.cc


Index: test/sanitizer_common/TestCases/Posix/fputs_puts.cc
===
--- test/sanitizer_common/TestCases/Posix/fputs_puts.cc
+++ test/sanitizer_common/TestCases/Posix/fputs_puts.cc
@@ -1,18 +1,12 @@
 // RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
 // CHECK: {{^foobar$}}
 
+#include 
 #include 
 
 int main(void) {
-  int r;
-
-  r = fputs("foo", stdout);
-  if (r < 0)
-return 1;
-
-  r = puts("bar");
-  if (r < 0)
-return 1;
+  assert(fputs("foo", stdout) >= 0);
+  assert(puts("bar") >= 0);
 
   return 0;
 }
Index: test/sanitizer_common/TestCases/Posix/fgets.cc
===
--- test/sanitizer_common/TestCases/Posix/fgets.cc
+++ test/sanitizer_common/TestCases/Posix/fgets.cc
@@ -1,20 +1,16 @@
 // RUN: %clangxx -g %s -o %t && %run %t
 
+#include 
 #include 
 
 int main(int argc, char **argv) {
-  FILE *fp;
-  char buf[2];
-  char *s;
-
-  fp = fopen(argv[0], "r");
-  if (!fp)
-return 1;
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
 
-  s = fgets(buf, sizeof(buf), fp);
-  if (!s)
-return 2;
+  char buf[2];
+  char *s = fgets(buf, sizeof(buf), fp);
+  assert(s);
 
-  fclose(fp);
+  assert(!fclose(fp));
   return 0;
 }


Index: test/sanitizer_common/TestCases/Posix/fputs_puts.cc
===
--- test/sanitizer_common/TestCases/Posix/fputs_puts.cc
+++ test/sanitizer_common/TestCases/Posix/fputs_puts.cc
@@ -1,18 +1,12 @@
 // RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
 // CHECK: {{^foobar$}}
 
+#include 
 #include 
 
 int main(void) {
-  int r;
-
-  r = fputs("foo", stdout);
-  if (r < 0)
-return 1;
-
-  r = puts("bar");
-  if (r < 0)
-return 1;
+  assert(fputs("foo", stdout) >= 0);
+  assert(puts("bar") >= 0);
 
   return 0;
 }
Index: test/sanitizer_common/TestCases/Posix/fgets.cc
===
--- test/sanitizer_common/TestCases/Posix/fgets.cc
+++ test/sanitizer_common/TestCases/Posix/fgets.cc
@@ -1,20 +1,16 @@
 // RUN: %clangxx -g %s -o %t && %run %t
 
+#include 
 #include 
 
 int main(int argc, char **argv) {
-  FILE *fp;
-  char buf[2];
-  char *s;
-
-  fp = fopen(argv[0], "r");
-  if (!fp)
-return 1;
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
 
-  s = fgets(buf, sizeof(buf), fp);
-  if (!s)
-return 2;
+  char buf[2];
+  char *s = fgets(buf, sizeof(buf), fp);
+  assert(s);
 
-  fclose(fp);
+  assert(!fclose(fp));
   return 0;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56149: [sanitizer_common] Rewrite more Posix tests to use asserts

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179693.
mgorny retitled this revision from "[sanitizer_common] Rewrite fgets/fputs/puts 
tests to use asserts" to "[sanitizer_common] Rewrite more Posix tests to use 
asserts".
mgorny edited the summary of this revision.
mgorny added a comment.

Updated to cover functions which used `exit(1)` too.


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

https://reviews.llvm.org/D56149

Files:
  test/sanitizer_common/TestCases/Posix/devname.cc
  test/sanitizer_common/TestCases/Posix/devname_r.cc
  test/sanitizer_common/TestCases/Posix/fgetln.cc
  test/sanitizer_common/TestCases/Posix/fgets.cc
  test/sanitizer_common/TestCases/Posix/fputs_puts.cc
  test/sanitizer_common/TestCases/Posix/lstat.cc

Index: test/sanitizer_common/TestCases/Posix/lstat.cc
===
--- test/sanitizer_common/TestCases/Posix/lstat.cc
+++ test/sanitizer_common/TestCases/Posix/lstat.cc
@@ -1,16 +1,14 @@
 // RUN: %clangxx -O0 -g %s -o %t && %run %t
 
+#include 
 #include 
 #include 
 
 int main(void) {
   struct stat st;
 
-  if (lstat("/dev/null", &st))
-exit(1);
-
-  if (!S_ISCHR(st.st_mode))
-exit(1);
+  assert(!lstat("/dev/null", &st));
+  assert(S_ISCHR(st.st_mode));
 
   return 0;
 }
Index: test/sanitizer_common/TestCases/Posix/fputs_puts.cc
===
--- test/sanitizer_common/TestCases/Posix/fputs_puts.cc
+++ test/sanitizer_common/TestCases/Posix/fputs_puts.cc
@@ -1,18 +1,12 @@
 // RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
 // CHECK: {{^foobar$}}
 
+#include 
 #include 
 
 int main(void) {
-  int r;
-
-  r = fputs("foo", stdout);
-  if (r < 0)
-return 1;
-
-  r = puts("bar");
-  if (r < 0)
-return 1;
+  assert(fputs("foo", stdout) >= 0);
+  assert(puts("bar") >= 0);
 
   return 0;
 }
Index: test/sanitizer_common/TestCases/Posix/fgets.cc
===
--- test/sanitizer_common/TestCases/Posix/fgets.cc
+++ test/sanitizer_common/TestCases/Posix/fgets.cc
@@ -1,20 +1,16 @@
 // RUN: %clangxx -g %s -o %t && %run %t
 
+#include 
 #include 
 
 int main(int argc, char **argv) {
-  FILE *fp;
-  char buf[2];
-  char *s;
-
-  fp = fopen(argv[0], "r");
-  if (!fp)
-return 1;
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
 
-  s = fgets(buf, sizeof(buf), fp);
-  if (!s)
-return 2;
+  char buf[2];
+  char *s = fgets(buf, sizeof(buf), fp);
+  assert(s);
 
-  fclose(fp);
+  assert(!fclose(fp));
   return 0;
 }
Index: test/sanitizer_common/TestCases/Posix/fgetln.cc
===
--- test/sanitizer_common/TestCases/Posix/fgetln.cc
+++ test/sanitizer_common/TestCases/Posix/fgetln.cc
@@ -1,24 +1,20 @@
 // RUN: %clangxx -O0 -g %s -o %t && %run %t
 // UNSUPPORTED: linux
 
+#include 
 #include 
 #include 
 
 int main(void) {
-  FILE *fp;
-  size_t len;
-  char *s;
-
-  fp = fopen("/etc/hosts", "r");
-  if (!fp)
-exit(1);
+  FILE *fp = fopen("/etc/hosts", "r");
+  assert(fp);
 
-  s = fgetln(fp, &len);
+  size_t len;
+  char *s = fgetln(fp, &len);
 
   printf("%.*s\n", (int)len, s);
 
-  if (fclose(fp) == EOF)
-exit(1);
+  assert(!fclose(fp));
 
   return 0;
 }
Index: test/sanitizer_common/TestCases/Posix/devname_r.cc
===
--- test/sanitizer_common/TestCases/Posix/devname_r.cc
+++ test/sanitizer_common/TestCases/Posix/devname_r.cc
@@ -4,6 +4,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 
@@ -12,17 +13,14 @@
   char name[100];
   mode_t type;
 
-  if (stat("/dev/null", &st))
-exit(1);
+  assert(!stat("/dev/null", &st));
 
   type = S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK;
 
 #if defined(__NetBSD__)
-  if (devname_r(st.st_rdev, type, name, sizeof(name)))
-exit(1);
+  assert(!devname_r(st.st_rdev, type, name, sizeof(name)));
 #else
-  if (!devname_r(st.st_rdev, type, name, sizeof(name)))
-exit(1);
+  assert(devname_r(st.st_rdev, type, name, sizeof(name)));
 #endif
 
   printf("%s\n", name);
Index: test/sanitizer_common/TestCases/Posix/devname.cc
===
--- test/sanitizer_common/TestCases/Posix/devname.cc
+++ test/sanitizer_common/TestCases/Posix/devname.cc
@@ -1,6 +1,7 @@
 // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
 // UNSUPPORTED: linux, solaris
 
+#include 
 #include 
 #include 
 #include 
@@ -9,11 +10,8 @@
   struct stat st;
   char *name;
 
-  if (stat("/dev/null", &st))
-exit(1);
-
-  if (!(name = devname(st.st_rdev, S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK)))
-exit(1);
+  assert(!stat("/dev/null", &st));
+  assert((name = devname(st.st_rdev, S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK)));
 
   printf("%s\n", name);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-co

[PATCH] D56150: [sanitizer_common] Fix devname_r() return type on !NetBSD

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek, emaste.

Update the interceptor for devname_r() to account for correct return
types on different platforms.  This function returns int on NetBSD
but char* on FreeBSD/OSX.  Noticed by @krytarowski.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56150

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc


Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7067,12 +7067,19 @@
 #endif
 
 #if SANITIZER_INTERCEPT_DEVNAME_R
-INTERCEPTOR(int, devname_r, u64 dev, u32 type, char *path, uptr len) {
+#if SANITIZER_NETBSD
+#define DEVNAME_R_RETTYPE int
+#define DEVNAME_R_SUCCESS(x) (!(x))
+#else
+#define DEVNAME_R_RETTYPE char*
+#define DEVNAME_R_SUCCESS(x) (x)
+#endif
+INTERCEPTOR(DEVNAME_R_RETTYPE, devname_r, u64 dev, u32 type, char *path, uptr 
len) {
   void *ctx;
-  int res;
+  DEVNAME_R_RETTYPE res;
   COMMON_INTERCEPTOR_ENTER(ctx, devname_r, dev, type, path, len);
   res = REAL(devname_r)(dev, type, path, len);
-  if (!res)
+  if (DEVNAME_R_SUCCESS(res))
 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, path, REAL(strlen)(path) + 1);
   return res;
 }


Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7067,12 +7067,19 @@
 #endif
 
 #if SANITIZER_INTERCEPT_DEVNAME_R
-INTERCEPTOR(int, devname_r, u64 dev, u32 type, char *path, uptr len) {
+#if SANITIZER_NETBSD
+#define DEVNAME_R_RETTYPE int
+#define DEVNAME_R_SUCCESS(x) (!(x))
+#else
+#define DEVNAME_R_RETTYPE char*
+#define DEVNAME_R_SUCCESS(x) (x)
+#endif
+INTERCEPTOR(DEVNAME_R_RETTYPE, devname_r, u64 dev, u32 type, char *path, uptr len) {
   void *ctx;
-  int res;
+  DEVNAME_R_RETTYPE res;
   COMMON_INTERCEPTOR_ENTER(ctx, devname_r, dev, type, path, len);
   res = REAL(devname_r)(dev, type, path, len);
-  if (!res)
+  if (DEVNAME_R_SUCCESS(res))
 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, path, REAL(strlen)(path) + 1);
   return res;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56150: [sanitizer_common] Fix devname_r() return type on !NetBSD

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179696.
mgorny added a comment.

Fixed lint.


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

https://reviews.llvm.org/D56150

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc


Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7067,12 +7067,20 @@
 #endif
 
 #if SANITIZER_INTERCEPT_DEVNAME_R
-INTERCEPTOR(int, devname_r, u64 dev, u32 type, char *path, uptr len) {
+#if SANITIZER_NETBSD
+#define DEVNAME_R_RETTYPE int
+#define DEVNAME_R_SUCCESS(x) (!(x))
+#else
+#define DEVNAME_R_RETTYPE char*
+#define DEVNAME_R_SUCCESS(x) (x)
+#endif
+INTERCEPTOR(DEVNAME_R_RETTYPE, devname_r, u64 dev, u32 type, char *path,
+uptr len) {
   void *ctx;
-  int res;
+  DEVNAME_R_RETTYPE res;
   COMMON_INTERCEPTOR_ENTER(ctx, devname_r, dev, type, path, len);
   res = REAL(devname_r)(dev, type, path, len);
-  if (!res)
+  if (DEVNAME_R_SUCCESS(res))
 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, path, REAL(strlen)(path) + 1);
   return res;
 }


Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7067,12 +7067,20 @@
 #endif
 
 #if SANITIZER_INTERCEPT_DEVNAME_R
-INTERCEPTOR(int, devname_r, u64 dev, u32 type, char *path, uptr len) {
+#if SANITIZER_NETBSD
+#define DEVNAME_R_RETTYPE int
+#define DEVNAME_R_SUCCESS(x) (!(x))
+#else
+#define DEVNAME_R_RETTYPE char*
+#define DEVNAME_R_SUCCESS(x) (x)
+#endif
+INTERCEPTOR(DEVNAME_R_RETTYPE, devname_r, u64 dev, u32 type, char *path,
+uptr len) {
   void *ctx;
-  int res;
+  DEVNAME_R_RETTYPE res;
   COMMON_INTERCEPTOR_ENTER(ctx, devname_r, dev, type, path, len);
   res = REAL(devname_r)(dev, type, path, len);
-  if (!res)
+  if (DEVNAME_R_SUCCESS(res))
 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, path, REAL(strlen)(path) + 1);
   return res;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56152: [sanitizer_common] Add tests for remaining *putc and *getc variants

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek.

Subject: [PATCH 5/5] [sanitizer_common] Add tests for remaining *putc and
 *getc variants

Add tests for the remaining character-oriented functions, that is:

- fputc(), putc() and putchar()
- getc_unlocked()
- putc_unlocked() and putchar_unlocked()

I'm omitting getchar_unlocked() as it relies on reading from stdin,
and it is unlikely for it to be implemented otherwise as an alias
to getc/fgetc.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56152

Files:
  test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
  test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
  test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc


Index: test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
@@ -0,0 +1,12 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: bc
+
+#include 
+#include 
+
+int main(void) {
+  assert(putc_unlocked('b', stdout) != EOF);
+  assert(putchar_unlocked('c') != EOF);
+
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
@@ -0,0 +1,20 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(getc_unlocked(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  // NB: ungetc_unlocked is apparently not present
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() works with getc_unlocked()
+  assert(getc_unlocked(fp) == 'X');
+
+  assert(!fclose(fp));
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
@@ -0,0 +1,13 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: abc
+
+#include 
+#include 
+
+int main(void) {
+  assert(fputc('a', stdout) != EOF);
+  assert(putc('b', stdout) != EOF);
+  assert(putchar('c') != EOF);
+
+  return 0;
+}


Index: test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
@@ -0,0 +1,12 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: bc
+
+#include 
+#include 
+
+int main(void) {
+  assert(putc_unlocked('b', stdout) != EOF);
+  assert(putchar_unlocked('c') != EOF);
+
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
@@ -0,0 +1,20 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(getc_unlocked(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  // NB: ungetc_unlocked is apparently not present
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() works with getc_unlocked()
+  assert(getc_unlocked(fp) == 'X');
+
+  assert(!fclose(fp));
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
@@ -0,0 +1,13 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: abc
+
+#include 
+#include 
+
+int main(void) {
+  assert(fputc('a', stdout) != EOF);
+  assert(putc('b', stdout) != EOF);
+  assert(putchar('c') != EOF);
+
+  return 0;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56153: [sanitizer_common] Add test for popen()

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek.

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56153

Files:
  test/sanitizer_common/TestCases/Posix/popen.cc


Index: test/sanitizer_common/TestCases/Posix/popen.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/popen.cc
@@ -0,0 +1,18 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: 1
+// CHECK-NEXT: 2
+
+#include 
+#include 
+
+int main(void) {
+  // use a tool that produces different output than input to verify
+  // that everything worked correctly
+  FILE *fp = popen("sort", "w");
+  assert(fp);
+  assert(fputs("2\n", fp) >= 0);
+  assert(fputs("1\n", fp) >= 0);
+  assert(pclose(fp) == 0);
+
+  return 0;
+}


Index: test/sanitizer_common/TestCases/Posix/popen.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/popen.cc
@@ -0,0 +1,18 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: 1
+// CHECK-NEXT: 2
+
+#include 
+#include 
+
+int main(void) {
+  // use a tool that produces different output than input to verify
+  // that everything worked correctly
+  FILE *fp = popen("sort", "w");
+  assert(fp);
+  assert(fputs("2\n", fp) >= 0);
+  assert(fputs("1\n", fp) >= 0);
+  assert(pclose(fp) == 0);
+
+  return 0;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56154: [sanitizer_common] Add tests for NetBSD funopen*()

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek.

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56154

Files:
  test/sanitizer_common/TestCases/NetBSD/funopen.cc
  test/sanitizer_common/TestCases/NetBSD/funopen2.cc

Index: test/sanitizer_common/TestCases/NetBSD/funopen2.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/NetBSD/funopen2.cc
@@ -0,0 +1,104 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+
+// CHECK: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: CLOSE CALLED
+// CHECK-NEXT: SEEK CALLED; off=100, whence=0
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: FLUSH CALLED
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: FLUSH CALLED
+
+#include 
+#include 
+#include 
+#include 
+
+int cookie_var;
+
+ssize_t f_read(void *cookie, void *buf, size_t len) {
+  assert(cookie == &cookie_var);
+  assert(len >= 6);
+  printf("READ CALLED; len=%zd\n", len);
+  return strlcpy((char*)buf, "test\n", len);
+}
+
+ssize_t f_write(void *cookie, const void *buf, size_t len) {
+  assert(cookie == &cookie_var);
+  char *data = strndup((char*)buf, len);
+  assert(data);
+  printf("WRITE CALLED: %s\n", data);
+  free(data);
+  return len;
+}
+
+off_t f_seek(void *cookie, off_t off, int whence) {
+  assert(cookie == &cookie_var);
+  assert(whence == SEEK_SET);
+  printf("SEEK CALLED; off=%d, whence=%d\n", (int)off, whence);
+  return off;
+}
+
+int f_flush(void *cookie) {
+  assert(cookie == &cookie_var);
+  printf("FLUSH CALLED\n");
+  return 0;
+}
+
+int f_close(void *cookie) {
+  assert(cookie == &cookie_var);
+  printf("CLOSE CALLED\n");
+  return 0;
+}
+
+int main(void) {
+  FILE *fp;
+  char buf[10];
+
+  // 1. read-only variant
+  fp = fropen2(&cookie_var, f_read);
+  assert(fp);
+  assert(fgets(buf, sizeof(buf), fp));
+  printf("READ: %s", buf);
+  assert(!fclose(fp));
+
+  // 2. write-only variant
+  fp = fwopen2(&cookie_var, f_write);
+  assert(fp);
+  assert(fputs("test", fp) >= 0);
+  assert(!fclose(fp));
+
+  // 3. read+write+close
+  fp = funopen2(&cookie_var, f_read, f_write, NULL, NULL, f_close);
+  assert(fp);
+  assert(fgets(buf, sizeof(buf), fp));
+  printf("READ: %s", buf);
+  assert(fputs("test", fp) >= 0);
+  assert(!fflush(fp));
+  assert(!fclose(fp));
+
+  // 4. read+seek
+  fp = funopen2(&cookie_var, f_read, NULL, f_seek, NULL, NULL);
+  assert(fp);
+  assert(fseek(fp, 100, SEEK_SET) == 0);
+  assert(fgets(buf, sizeof(buf), fp));
+  printf("READ: %s", buf);
+  assert(!fclose(fp));
+
+  // 5. write+flush
+  fp = funopen2(&cookie_var, NULL, f_write, NULL, f_flush, NULL);
+  assert(fp);
+  assert(fputs("test", fp) >= 0);
+  assert(!fflush(fp));
+  assert(fputs("test", fp) >= 0);
+  // NB: fclose() also implicitly calls flush
+  assert(!fclose(fp));
+
+  return 0;
+}
Index: test/sanitizer_common/TestCases/NetBSD/funopen.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/NetBSD/funopen.cc
@@ -0,0 +1,84 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+
+// CHECK: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: CLOSE CALLED
+// CHECK-NEXT: SEEK CALLED; off=100, whence=0
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+
+#include 
+#include 
+#include 
+#include 
+
+int cookie_var;
+
+int f_read(void *cookie, char *buf, int len) {
+  assert(cookie == &cookie_var);
+  assert(len >= 6);
+  printf("READ CALLED; len=%d\n", len);
+  return strlcpy(buf, "test\n", len);
+}
+
+int f_write(void *cookie, const char *buf, int len) {
+  assert(cookie == &cookie_var);
+  char *data = strndup(buf, len);
+  assert(data);
+  printf("WRITE CALLED: %s\n", data);
+  free(data);
+  return len;
+}
+
+off_t f_seek(void *cookie, off_t off, int whence) {
+  assert(cookie == &cookie_var);
+  assert(whence == SEEK_SET);
+  printf("SEEK CALLED; off=%d, whence=%d\n", (int)off, whence);
+  return off;
+}
+
+int f_close(void *cookie) {
+  assert(cookie == &cookie_var);
+  printf("CLOSE CALLED\n");
+  return 0;
+}
+
+int main(void) {
+  FILE *fp;
+  char buf[10];
+
+  // 1. read-only variant
+  fp = fropen(&cookie_var, f_read);
+  assert(fp);
+  assert(fgets(buf, sizeof(buf), fp));
+  printf("READ: %s", buf);
+  assert(!fclose(fp));
+
+  // 2. write-only variant
+  fp = fwopen(&cookie_var, f_write);
+  assert(fp);
+  assert(fputs("test", fp) >= 0);
+  assert(!fclose(fp));
+
+  // 3. read+write+close
+  fp = funopen(&cookie_var, f_read, f_write, NULL

[PATCH] D56152: [sanitizer_common] Add tests for remaining *putc and *getc variants

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

In D56152#1342331 , @krytarowski wrote:

> Are all the functions available for FreeBSD, NetBSD, Linux, Android, Solaris 
> an Darwin?


I don't know. I suppose the easiest way to check would be to commit it and see 
what happens. Then address the fallout.

> I would include a test for `getchar_unlocked()` anyway, even if it's an alias 
> in most/all implementations.

I suppose I could do that but I'd have to pipe some data into the stdin.


Repository:
  rCRT Compiler Runtime

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

https://reviews.llvm.org/D56152



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56150: [sanitizer_common] Fix devname_r() return type on !NetBSD

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179707.
mgorny added a comment.

Updated variable style.


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

https://reviews.llvm.org/D56150

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc


Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7067,12 +7067,19 @@
 #endif
 
 #if SANITIZER_INTERCEPT_DEVNAME_R
-INTERCEPTOR(int, devname_r, u64 dev, u32 type, char *path, uptr len) {
+#if SANITIZER_NETBSD
+#define DEVNAME_R_RETTYPE int
+#define DEVNAME_R_SUCCESS(x) (!(x))
+#else
+#define DEVNAME_R_RETTYPE char*
+#define DEVNAME_R_SUCCESS(x) (x)
+#endif
+INTERCEPTOR(DEVNAME_R_RETTYPE, devname_r, u64 dev, u32 type, char *path,
+uptr len) {
   void *ctx;
-  int res;
   COMMON_INTERCEPTOR_ENTER(ctx, devname_r, dev, type, path, len);
-  res = REAL(devname_r)(dev, type, path, len);
-  if (!res)
+  DEVNAME_R_RETTYPE res = REAL(devname_r)(dev, type, path, len);
+  if (DEVNAME_R_SUCCESS(res))
 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, path, REAL(strlen)(path) + 1);
   return res;
 }


Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7067,12 +7067,19 @@
 #endif
 
 #if SANITIZER_INTERCEPT_DEVNAME_R
-INTERCEPTOR(int, devname_r, u64 dev, u32 type, char *path, uptr len) {
+#if SANITIZER_NETBSD
+#define DEVNAME_R_RETTYPE int
+#define DEVNAME_R_SUCCESS(x) (!(x))
+#else
+#define DEVNAME_R_RETTYPE char*
+#define DEVNAME_R_SUCCESS(x) (x)
+#endif
+INTERCEPTOR(DEVNAME_R_RETTYPE, devname_r, u64 dev, u32 type, char *path,
+uptr len) {
   void *ctx;
-  int res;
   COMMON_INTERCEPTOR_ENTER(ctx, devname_r, dev, type, path, len);
-  res = REAL(devname_r)(dev, type, path, len);
-  if (!res)
+  DEVNAME_R_RETTYPE res = REAL(devname_r)(dev, type, path, len);
+  if (DEVNAME_R_SUCCESS(res))
 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, path, REAL(strlen)(path) + 1);
   return res;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56157: [sanitizer_common] Implement popen, popenve, pclose interceptors

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek.

Implement the interceptors for popen(), pclose() and popenve()
functions.  The first two are POSIX, the third one is specific
to NetBSD.  popen() spawns a process and creates a FILE object piping
data from/to that process.  pclose() closes the pipe and waits for
the process to terminate appropriately.

For the purpose of popen(), a new COMMON_INTERCEPTOR_PIPE_OPEN macro is
added that is like COMMON_INTERCEPTOR_FILE_OPEN, except it is passed
the new FILE* and no path.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56157

Files:
  lib/esan/esan_interceptors.cpp
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_interceptors.h
  lib/tsan/rtl/tsan_interceptors.cc

Index: lib/tsan/rtl/tsan_interceptors.cc
===
--- lib/tsan/rtl/tsan_interceptors.cc
+++ lib/tsan/rtl/tsan_interceptors.cc
@@ -2256,6 +2256,12 @@
 if (fd >= 0) FdFileCreate(thr, pc, fd);   \
   }
 
+#define COMMON_INTERCEPTOR_PIPE_OPEN(ctx, file) \
+  if (file) {   \
+int fd = fileno_unlocked(file); \
+if (fd >= 0) FdFileCreate(thr, pc, fd); \
+  }
+
 #define COMMON_INTERCEPTOR_FILE_CLOSE(ctx, file) \
   if (file) {\
 int fd = fileno_unlocked(file);  \
Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -546,4 +546,8 @@
 #define SANITIZER_INTERCEPT_CDB SI_NETBSD
 #define SANITIZER_INTERCEPT_VIS (SI_NETBSD || SI_FREEBSD)
 
+#define SANITIZER_INTERCEPT_POPEN SI_POSIX
+#define SANITIZER_INTERCEPT_POPENVE SI_NETBSD
+#define SANITIZER_INTERCEPT_PCLOSE SI_POSIX
+
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -178,6 +178,10 @@
 #define COMMON_INTERCEPTOR_FILE_OPEN(ctx, file, path) {}
 #endif
 
+#ifndef COMMON_INTERCEPTOR_PIPE_OPEN
+#define COMMON_INTERCEPTOR_PIPE_OPEN(ctx, file) {}
+#endif
+
 #ifndef COMMON_INTERCEPTOR_FILE_CLOSE
 #define COMMON_INTERCEPTOR_FILE_CLOSE(ctx, file) {}
 #endif
@@ -9058,6 +9062,77 @@
 #define INIT_CDB
 #endif
 
+#if SANITIZER_INTERCEPT_POPEN
+INTERCEPTOR(__sanitizer_FILE *, popen, const char *command, const char *type) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, popen, command, type);
+  if (command)
+COMMON_INTERCEPTOR_READ_RANGE(ctx, command, REAL(strlen)(command) + 1);
+  if (type)
+COMMON_INTERCEPTOR_READ_RANGE(ctx, type, REAL(strlen)(type) + 1);
+  __sanitizer_FILE *res = REAL(popen)(command, type);
+  COMMON_INTERCEPTOR_PIPE_OPEN(ctx, res);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_POPEN COMMON_INTERCEPT_FUNCTION(popen)
+#else
+#define INIT_POPEN
+#endif
+
+#if SANITIZER_INTERCEPT_POPENVE
+INTERCEPTOR(__sanitizer_FILE *, popenve, const char *path,
+char *const *argv, char *const *envp, const char *type) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, popenve, path, argv, envp, type);
+  if (path)
+COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1);
+  if (argv) {
+for (char *const *pa = argv; ; ++pa) {
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, pa, sizeof(char **));
+  if (!*pa)
+break;
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, *pa, REAL(strlen)(*pa) + 1);
+}
+  }
+  if (envp) {
+for (char *const *pa = envp; ; ++pa) {
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, pa, sizeof(char **));
+  if (!*pa)
+break;
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, *pa, REAL(strlen)(*pa) + 1);
+}
+  }
+  if (type)
+COMMON_INTERCEPTOR_READ_RANGE(ctx, type, REAL(strlen)(type) + 1);
+  __sanitizer_FILE *res = REAL(popenve)(path, argv, envp, type);
+  COMMON_INTERCEPTOR_PIPE_OPEN(ctx, res);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_POPENVE COMMON_INTERCEPT_FUNCTION(popenve)
+#else
+#define INIT_POPENVE
+#endif
+
+#if SANITIZER_INTERCEPT_PCLOSE
+INTERCEPTOR(int, pclose, __sanitizer_FILE *fp) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, pclose, fp);
+  COMMON_INTERCEPTOR_FILE_CLOSE(ctx, fp);
+  const FileMetadata *m = GetInterceptorMetadata(fp);
+  int res = REAL(pclose)(fp);
+  if (m) {
+COMMON_INTERCEPTOR_INITIALIZE_RANGE(*m->addr, *m->size);
+DeleteInterceptorMetadata(fp);
+  }
+  return res;
+}
+#define INIT_PCLOSE COMMON_INTERCEPT_FUNCTION(pclose);
+#else
+#define INIT_PCLOSE
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(Metadata

[PATCH] D56152: [sanitizer_common] Add tests for more *putc and *getc variants

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179711.
mgorny retitled this revision from "[sanitizer_common] Add tests for remaining 
*putc and *getc variants" to "[sanitizer_common] Add tests for more *putc and 
*getc variants".
mgorny edited the summary of this revision.
mgorny added a comment.

Updated description.


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

https://reviews.llvm.org/D56152

Files:
  test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
  test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
  test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc


Index: test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
@@ -0,0 +1,12 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: bc
+
+#include 
+#include 
+
+int main(void) {
+  assert(putc_unlocked('b', stdout) != EOF);
+  assert(putchar_unlocked('c') != EOF);
+
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
@@ -0,0 +1,20 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(getc_unlocked(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  // NB: ungetc_unlocked is apparently not present
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() works with getc_unlocked()
+  assert(getc_unlocked(fp) == 'X');
+
+  assert(!fclose(fp));
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
@@ -0,0 +1,13 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: abc
+
+#include 
+#include 
+
+int main(void) {
+  assert(fputc('a', stdout) != EOF);
+  assert(putc('b', stdout) != EOF);
+  assert(putchar('c') != EOF);
+
+  return 0;
+}


Index: test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
@@ -0,0 +1,12 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: bc
+
+#include 
+#include 
+
+int main(void) {
+  assert(putc_unlocked('b', stdout) != EOF);
+  assert(putchar_unlocked('c') != EOF);
+
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
@@ -0,0 +1,20 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(getc_unlocked(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  // NB: ungetc_unlocked is apparently not present
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() works with getc_unlocked()
+  assert(getc_unlocked(fp) == 'X');
+
+  assert(!fclose(fp));
+  return 0;
+}
Index: test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
@@ -0,0 +1,13 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: abc
+
+#include 
+#include 
+
+int main(void) {
+  assert(fputc('a', stdout) != EOF);
+  assert(putc('b', stdout) != EOF);
+  assert(putchar('c') != EOF);
+
+  return 0;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56153: [sanitizer_common] Add test for popen()

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179712.
mgorny added a comment.

Added assertion verifying that `fileno(fp)` works.


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

https://reviews.llvm.org/D56153

Files:
  test/sanitizer_common/TestCases/Posix/popen.cc


Index: test/sanitizer_common/TestCases/Posix/popen.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/popen.cc
@@ -0,0 +1,23 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: 1
+// CHECK-NEXT: 2
+
+#include 
+#include 
+
+int main(void) {
+  // use a tool that produces different output than input to verify
+  // that everything worked correctly
+  FILE *fp = popen("sort", "w");
+  assert(fp);
+
+  // verify that fileno() returns a meaningful descriptor (needed
+  // for the implementation of TSan)
+  assert(fileno(fp) != -1);
+
+  assert(fputs("2\n", fp) >= 0);
+  assert(fputs("1\n", fp) >= 0);
+  assert(pclose(fp) == 0);
+
+  return 0;
+}


Index: test/sanitizer_common/TestCases/Posix/popen.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/popen.cc
@@ -0,0 +1,23 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: 1
+// CHECK-NEXT: 2
+
+#include 
+#include 
+
+int main(void) {
+  // use a tool that produces different output than input to verify
+  // that everything worked correctly
+  FILE *fp = popen("sort", "w");
+  assert(fp);
+
+  // verify that fileno() returns a meaningful descriptor (needed
+  // for the implementation of TSan)
+  assert(fileno(fp) != -1);
+
+  assert(fputs("2\n", fp) >= 0);
+  assert(fputs("1\n", fp) >= 0);
+  assert(pclose(fp) == 0);
+
+  return 0;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56154: [sanitizer_common] Add tests for NetBSD funopen*()

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179713.
mgorny added a comment.

Added assertions for `fileno()` returning -1.


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

https://reviews.llvm.org/D56154

Files:
  test/sanitizer_common/TestCases/NetBSD/funopen.cc
  test/sanitizer_common/TestCases/NetBSD/funopen2.cc

Index: test/sanitizer_common/TestCases/NetBSD/funopen2.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/NetBSD/funopen2.cc
@@ -0,0 +1,110 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+
+// CHECK: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: CLOSE CALLED
+// CHECK-NEXT: SEEK CALLED; off=100, whence=0
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: FLUSH CALLED
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: FLUSH CALLED
+
+#include 
+#include 
+#include 
+#include 
+
+int cookie_var;
+
+ssize_t f_read(void *cookie, void *buf, size_t len) {
+  assert(cookie == &cookie_var);
+  assert(len >= 6);
+  printf("READ CALLED; len=%zd\n", len);
+  return strlcpy((char*)buf, "test\n", len);
+}
+
+ssize_t f_write(void *cookie, const void *buf, size_t len) {
+  assert(cookie == &cookie_var);
+  char *data = strndup((char*)buf, len);
+  assert(data);
+  printf("WRITE CALLED: %s\n", data);
+  free(data);
+  return len;
+}
+
+off_t f_seek(void *cookie, off_t off, int whence) {
+  assert(cookie == &cookie_var);
+  assert(whence == SEEK_SET);
+  printf("SEEK CALLED; off=%d, whence=%d\n", (int)off, whence);
+  return off;
+}
+
+int f_flush(void *cookie) {
+  assert(cookie == &cookie_var);
+  printf("FLUSH CALLED\n");
+  return 0;
+}
+
+int f_close(void *cookie) {
+  assert(cookie == &cookie_var);
+  printf("CLOSE CALLED\n");
+  return 0;
+}
+
+int main(void) {
+  FILE *fp;
+  char buf[10];
+
+  // 1. read-only variant
+  fp = fropen2(&cookie_var, f_read);
+  assert(fp);
+  // verify that fileno() does not crash or report nonsense
+  assert(fileno(fp) == -1);
+  assert(fgets(buf, sizeof(buf), fp));
+  printf("READ: %s", buf);
+  assert(!fclose(fp));
+
+  // 2. write-only variant
+  fp = fwopen2(&cookie_var, f_write);
+  assert(fp);
+  assert(fileno(fp) == -1);
+  assert(fputs("test", fp) >= 0);
+  assert(!fclose(fp));
+
+  // 3. read+write+close
+  fp = funopen2(&cookie_var, f_read, f_write, NULL, NULL, f_close);
+  assert(fp);
+  assert(fileno(fp) == -1);
+  assert(fgets(buf, sizeof(buf), fp));
+  printf("READ: %s", buf);
+  assert(fputs("test", fp) >= 0);
+  assert(!fflush(fp));
+  assert(!fclose(fp));
+
+  // 4. read+seek
+  fp = funopen2(&cookie_var, f_read, NULL, f_seek, NULL, NULL);
+  assert(fp);
+  assert(fileno(fp) == -1);
+  assert(fseek(fp, 100, SEEK_SET) == 0);
+  assert(fgets(buf, sizeof(buf), fp));
+  printf("READ: %s", buf);
+  assert(!fclose(fp));
+
+  // 5. write+flush
+  fp = funopen2(&cookie_var, NULL, f_write, NULL, f_flush, NULL);
+  assert(fp);
+  assert(fileno(fp) == -1);
+  assert(fputs("test", fp) >= 0);
+  assert(!fflush(fp));
+  assert(fputs("test", fp) >= 0);
+  // NB: fclose() also implicitly calls flush
+  assert(!fclose(fp));
+
+  return 0;
+}
Index: test/sanitizer_common/TestCases/NetBSD/funopen.cc
===
--- /dev/null
+++ test/sanitizer_common/TestCases/NetBSD/funopen.cc
@@ -0,0 +1,89 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+
+// CHECK: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: CLOSE CALLED
+// CHECK-NEXT: SEEK CALLED; off=100, whence=0
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+
+#include 
+#include 
+#include 
+#include 
+
+int cookie_var;
+
+int f_read(void *cookie, char *buf, int len) {
+  assert(cookie == &cookie_var);
+  assert(len >= 6);
+  printf("READ CALLED; len=%d\n", len);
+  return strlcpy(buf, "test\n", len);
+}
+
+int f_write(void *cookie, const char *buf, int len) {
+  assert(cookie == &cookie_var);
+  char *data = strndup(buf, len);
+  assert(data);
+  printf("WRITE CALLED: %s\n", data);
+  free(data);
+  return len;
+}
+
+off_t f_seek(void *cookie, off_t off, int whence) {
+  assert(cookie == &cookie_var);
+  assert(whence == SEEK_SET);
+  printf("SEEK CALLED; off=%d, whence=%d\n", (int)off, whence);
+  return off;
+}
+
+int f_close(void *cookie) {
+  assert(cookie == &cookie_var);
+  printf("CLOSE CALLED\n");
+  return 0;
+}
+
+int main(void) {
+  FILE *fp;
+  char buf[10];
+
+  // 1. read-only variant
+  fp = fropen(&cookie_var, f_read);
+  assert(fp);
+  // verify that fileno() does not crash or report nonsense
+  assert(fileno(fp) == -1);
+  assert(fge

[PATCH] D56158: [sanitizer_common] Implement funopen*() interceptors for NetBSD

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek.

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56158

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_interceptors.h


Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -549,5 +549,7 @@
 #define SANITIZER_INTERCEPT_POPEN SI_POSIX
 #define SANITIZER_INTERCEPT_POPENVE SI_NETBSD
 #define SANITIZER_INTERCEPT_PCLOSE SI_POSIX
+#define SANITIZER_INTERCEPT_FUNOPEN SI_NETBSD
+#define SANITIZER_INTERCEPT_FUNOPEN2 SI_NETBSD
 
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -9133,6 +9133,45 @@
 #define INIT_PCLOSE
 #endif
 
+#if SANITIZER_INTERCEPT_FUNOPEN
+INTERCEPTOR(__sanitizer_FILE *, funopen, void *cookie,
+int (*readfn)(void *cookie, char *buf, int len),
+int (*writefn)(void *cookie, const char *buf, int len),
+OFF_T (*seekfn)(void *cookie, OFF_T pos, int whence),
+int (*closefn)(void *cookie)) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, funopen, cookie, readfn, writefn,
+   seekfn, closefn);
+  __sanitizer_FILE *res = REAL(funopen)(cookie, readfn, writefn, seekfn,
+closefn);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_FUNOPEN COMMON_INTERCEPT_FUNCTION(funopen)
+#else
+#define INIT_FUNOPEN
+#endif
+
+#if SANITIZER_INTERCEPT_FUNOPEN2
+INTERCEPTOR(__sanitizer_FILE *, funopen2, void *cookie,
+SSIZE_T (*readfn)(void *cookie, void *buf, SIZE_T len),
+SSIZE_T (*writefn)(void *cookie, const void *buf, SIZE_T len),
+OFF_T (*seekfn)(void *cookie, OFF_T pos, int whence),
+int (*flushfn)(void *cookie),
+int (*closefn)(void *cookie)) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, funopen2, cookie, readfn, writefn,
+   seekfn, flushfn, closefn);
+  __sanitizer_FILE *res = REAL(funopen2)(cookie, readfn, writefn, seekfn,
+ flushfn, closefn);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_FUNOPEN2 COMMON_INTERCEPT_FUNCTION(funopen2)
+#else
+#define INIT_FUNOPEN2
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
   interceptor_metadata_map =
@@ -9416,6 +9455,8 @@
   INIT_POPEN;
   INIT_POPENVE;
   INIT_PCLOSE;
+  INIT_FUNOPEN;
+  INIT_FUNOPEN2;
 
   INIT___PRINTF_CHK;
 }


Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -549,5 +549,7 @@
 #define SANITIZER_INTERCEPT_POPEN SI_POSIX
 #define SANITIZER_INTERCEPT_POPENVE SI_NETBSD
 #define SANITIZER_INTERCEPT_PCLOSE SI_POSIX
+#define SANITIZER_INTERCEPT_FUNOPEN SI_NETBSD
+#define SANITIZER_INTERCEPT_FUNOPEN2 SI_NETBSD
 
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -9133,6 +9133,45 @@
 #define INIT_PCLOSE
 #endif
 
+#if SANITIZER_INTERCEPT_FUNOPEN
+INTERCEPTOR(__sanitizer_FILE *, funopen, void *cookie,
+int (*readfn)(void *cookie, char *buf, int len),
+int (*writefn)(void *cookie, const char *buf, int len),
+OFF_T (*seekfn)(void *cookie, OFF_T pos, int whence),
+int (*closefn)(void *cookie)) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, funopen, cookie, readfn, writefn,
+   seekfn, closefn);
+  __sanitizer_FILE *res = REAL(funopen)(cookie, readfn, writefn, seekfn,
+closefn);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_FUNOPEN COMMON_INTERCEPT_FUNCTION(funopen)
+#else
+#define INIT_FUNOPEN
+#endif
+
+#if SANITIZER_INTERCEPT_FUNOPEN2
+INTERCEPTOR(__sanitizer_FILE *, funopen2, void *cookie,
+SSIZE_T (*readfn)(void *cookie, void *buf, SIZE_T len),
+SSIZE_T (*writefn)(void *cookie, const void *buf, SIZE_T len),
+OFF_T (*seekfn)(void *cookie, OFF_T pos, int whence),
+int (*flushfn)(void *cookie),
+int (*closefn)(void *cookie)) {
+  

[PATCH] D56158: [sanitizer_common] Implement funopen*() interceptors for NetBSD

2018-12-30 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179722.
mgorny added a comment.

Implemented wrappers as requested.


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

https://reviews.llvm.org/D56158

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_interceptors.h
  lib/sanitizer_common/sanitizer_platform_limits_netbsd.h

Index: lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
===
--- lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
+++ lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
@@ -2319,6 +2319,7 @@
   void *hash;
   uptr key_counter;
 };
+
 }  // namespace __sanitizer
 
 #define CHECK_TYPE_SIZE(TYPE) \
Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -549,5 +549,7 @@
 #define SANITIZER_INTERCEPT_POPEN SI_POSIX
 #define SANITIZER_INTERCEPT_POPENVE SI_NETBSD
 #define SANITIZER_INTERCEPT_PCLOSE SI_POSIX
+#define SANITIZER_INTERCEPT_FUNOPEN SI_NETBSD
+#define SANITIZER_INTERCEPT_FUNOPEN2 SI_NETBSD
 
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -9133,6 +9133,161 @@
 #define INIT_PCLOSE
 #endif
 
+#if SANITIZER_INTERCEPT_FUNOPEN
+typedef int (*funopen_readfn)(void *cookie, char *buf, int len);
+typedef int (*funopen_writefn)(void *cookie, const char *buf, int len);
+typedef OFF_T (*funopen_seekfn)(void *cookie, OFF_T offset, int whence);
+typedef int (*funopen_closefn)(void *cookie);
+
+struct WrappedCookie {
+  void *real_cookie;
+  funopen_readfn real_read;
+  funopen_writefn real_write;
+  funopen_seekfn real_seek;
+  funopen_closefn real_close;
+};
+
+static int wrapped_read(void *cookie, char *buf, int len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
+  funopen_readfn real_read = wrapped_cookie->real_read;
+  return real_read(wrapped_cookie->real_cookie, buf, len);
+}
+
+static int wrapped_write(void *cookie, const char *buf, int len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
+  funopen_writefn real_write = wrapped_cookie->real_write;
+  return real_write(wrapped_cookie->real_cookie, buf, len);
+}
+
+static OFF_T wrapped_seek(void *cookie, OFF_T offset, int whence) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
+  funopen_seekfn real_seek = wrapped_cookie->real_seek;
+  return real_seek(wrapped_cookie->real_cookie, offset, whence);
+}
+
+static int wrapped_close(void *cookie) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(1);
+  WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
+  funopen_closefn real_close = wrapped_cookie->real_close;
+  int res = real_close(wrapped_cookie->real_cookie);
+  InternalFree(wrapped_cookie);
+  return res;
+}
+
+INTERCEPTOR(__sanitizer_FILE *, funopen, void *cookie, funopen_readfn readfn,
+funopen_writefn writefn, funopen_seekfn seekfn,
+funopen_closefn closefn) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, funopen, cookie, readfn, writefn,
+   seekfn, closefn);
+
+  WrappedCookie *wrapped_cookie =
+  (WrappedCookie *)InternalAlloc(sizeof(WrappedCookie));
+  wrapped_cookie->real_cookie = cookie;
+  wrapped_cookie->real_read = readfn;
+  wrapped_cookie->real_write = writefn;
+  wrapped_cookie->real_seek = seekfn;
+  wrapped_cookie->real_close = closefn;
+
+  __sanitizer_FILE *res = REAL(funopen)(wrapped_cookie,
+readfn  ? wrapped_read  : nullptr,
+writefn ? wrapped_write : nullptr,
+seekfn  ? wrapped_seek  : nullptr,
+closefn ? wrapped_close : nullptr);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_FUNOPEN COMMON_INTERCEPT_FUNCTION(funopen)
+#else
+#define INIT_FUNOPEN
+#endif
+
+#if SANITIZER_INTERCEPT_FUNOPEN2
+typedef SSIZE_T (*funopen2_readfn)(void *cookie, void *buf, SIZE_T len);
+typedef SSIZE_T (*funopen2_writefn)(void *cookie, const void *buf, SIZE_T len);
+typedef OFF_T (*funopen2_seekfn)(void *cookie, OFF_T offset, int whence);
+typedef int (*funopen2_flushfn)(void *cookie);
+typedef int (*funopen2_closefn)(void *cookie);
+
+struct WrappedCookie2 {
+  void *real_cookie;
+  funopen2_readfn real_read;
+  funopen2_writefn real_write;
+  funopen2_seekfn real_seek;
+  funopen2_flushfn real_flush;
+  funopen2_closefn real_close;
+};
+
+static SSIZE_T wrapped_read2(void

[PATCH] D56158: [sanitizer_common] Implement funopen*() interceptors for NetBSD

2018-12-30 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179723.
mgorny added a comment.

Fixed accidental whitespace change.


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

https://reviews.llvm.org/D56158

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_interceptors.h

Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -549,5 +549,7 @@
 #define SANITIZER_INTERCEPT_POPEN SI_POSIX
 #define SANITIZER_INTERCEPT_POPENVE SI_NETBSD
 #define SANITIZER_INTERCEPT_PCLOSE SI_POSIX
+#define SANITIZER_INTERCEPT_FUNOPEN SI_NETBSD
+#define SANITIZER_INTERCEPT_FUNOPEN2 SI_NETBSD
 
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -9133,6 +9133,161 @@
 #define INIT_PCLOSE
 #endif
 
+#if SANITIZER_INTERCEPT_FUNOPEN
+typedef int (*funopen_readfn)(void *cookie, char *buf, int len);
+typedef int (*funopen_writefn)(void *cookie, const char *buf, int len);
+typedef OFF_T (*funopen_seekfn)(void *cookie, OFF_T offset, int whence);
+typedef int (*funopen_closefn)(void *cookie);
+
+struct WrappedCookie {
+  void *real_cookie;
+  funopen_readfn real_read;
+  funopen_writefn real_write;
+  funopen_seekfn real_seek;
+  funopen_closefn real_close;
+};
+
+static int wrapped_read(void *cookie, char *buf, int len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
+  funopen_readfn real_read = wrapped_cookie->real_read;
+  return real_read(wrapped_cookie->real_cookie, buf, len);
+}
+
+static int wrapped_write(void *cookie, const char *buf, int len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
+  funopen_writefn real_write = wrapped_cookie->real_write;
+  return real_write(wrapped_cookie->real_cookie, buf, len);
+}
+
+static OFF_T wrapped_seek(void *cookie, OFF_T offset, int whence) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
+  funopen_seekfn real_seek = wrapped_cookie->real_seek;
+  return real_seek(wrapped_cookie->real_cookie, offset, whence);
+}
+
+static int wrapped_close(void *cookie) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(1);
+  WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
+  funopen_closefn real_close = wrapped_cookie->real_close;
+  int res = real_close(wrapped_cookie->real_cookie);
+  InternalFree(wrapped_cookie);
+  return res;
+}
+
+INTERCEPTOR(__sanitizer_FILE *, funopen, void *cookie, funopen_readfn readfn,
+funopen_writefn writefn, funopen_seekfn seekfn,
+funopen_closefn closefn) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, funopen, cookie, readfn, writefn,
+   seekfn, closefn);
+
+  WrappedCookie *wrapped_cookie =
+  (WrappedCookie *)InternalAlloc(sizeof(WrappedCookie));
+  wrapped_cookie->real_cookie = cookie;
+  wrapped_cookie->real_read = readfn;
+  wrapped_cookie->real_write = writefn;
+  wrapped_cookie->real_seek = seekfn;
+  wrapped_cookie->real_close = closefn;
+
+  __sanitizer_FILE *res = REAL(funopen)(wrapped_cookie,
+readfn  ? wrapped_read  : nullptr,
+writefn ? wrapped_write : nullptr,
+seekfn  ? wrapped_seek  : nullptr,
+closefn ? wrapped_close : nullptr);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_FUNOPEN COMMON_INTERCEPT_FUNCTION(funopen)
+#else
+#define INIT_FUNOPEN
+#endif
+
+#if SANITIZER_INTERCEPT_FUNOPEN2
+typedef SSIZE_T (*funopen2_readfn)(void *cookie, void *buf, SIZE_T len);
+typedef SSIZE_T (*funopen2_writefn)(void *cookie, const void *buf, SIZE_T len);
+typedef OFF_T (*funopen2_seekfn)(void *cookie, OFF_T offset, int whence);
+typedef int (*funopen2_flushfn)(void *cookie);
+typedef int (*funopen2_closefn)(void *cookie);
+
+struct WrappedCookie2 {
+  void *real_cookie;
+  funopen2_readfn real_read;
+  funopen2_writefn real_write;
+  funopen2_seekfn real_seek;
+  funopen2_flushfn real_flush;
+  funopen2_closefn real_close;
+};
+
+static SSIZE_T wrapped_read2(void *cookie, void *buf, SIZE_T len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedCookie2 *wrapped_cookie = (WrappedCookie2 *)cookie;
+  funopen2_readfn real_read = wrapped_cookie->real_read;
+  return real_read(wrapped_cookie->real_cookie, buf, len);
+}
+
+static SSIZE_T wrapped_write2(void *cookie, const void *buf, SIZE_T len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedCookie2 *wrapped_cookie = (WrappedCookie2 *)cook

[PATCH] D56158: [sanitizer_common] Implement funopen*() interceptors for NetBSD

2018-12-30 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179728.
mgorny added a comment.

Renamed stuff as requested.


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

https://reviews.llvm.org/D56158

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_interceptors.h

Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -549,5 +549,7 @@
 #define SANITIZER_INTERCEPT_POPEN SI_POSIX
 #define SANITIZER_INTERCEPT_POPENVE SI_NETBSD
 #define SANITIZER_INTERCEPT_PCLOSE SI_POSIX
+#define SANITIZER_INTERCEPT_FUNOPEN SI_NETBSD
+#define SANITIZER_INTERCEPT_FUNOPEN2 SI_NETBSD
 
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -9133,6 +9133,166 @@
 #define INIT_PCLOSE
 #endif
 
+#if SANITIZER_INTERCEPT_FUNOPEN
+typedef int (*funopen_readfn)(void *cookie, char *buf, int len);
+typedef int (*funopen_writefn)(void *cookie, const char *buf, int len);
+typedef OFF_T (*funopen_seekfn)(void *cookie, OFF_T offset, int whence);
+typedef int (*funopen_closefn)(void *cookie);
+
+struct WrappedFunopenCookie {
+  void *real_cookie;
+  funopen_readfn real_read;
+  funopen_writefn real_write;
+  funopen_seekfn real_seek;
+  funopen_closefn real_close;
+};
+
+static int wrapped_funopen_read(void *cookie, char *buf, int len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedFunopenCookie *wrapped_cookie = (WrappedFunopenCookie *)cookie;
+  funopen_readfn real_read = wrapped_cookie->real_read;
+  return real_read(wrapped_cookie->real_cookie, buf, len);
+}
+
+static int wrapped_funopen_write(void *cookie, const char *buf, int len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedFunopenCookie *wrapped_cookie = (WrappedFunopenCookie *)cookie;
+  funopen_writefn real_write = wrapped_cookie->real_write;
+  return real_write(wrapped_cookie->real_cookie, buf, len);
+}
+
+static OFF_T wrapped_funopen_seek(void *cookie, OFF_T offset, int whence) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedFunopenCookie *wrapped_cookie = (WrappedFunopenCookie *)cookie;
+  funopen_seekfn real_seek = wrapped_cookie->real_seek;
+  return real_seek(wrapped_cookie->real_cookie, offset, whence);
+}
+
+static int wrapped_funopen_close(void *cookie) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(1);
+  WrappedFunopenCookie *wrapped_cookie = (WrappedFunopenCookie *)cookie;
+  funopen_closefn real_close = wrapped_cookie->real_close;
+  int res = real_close(wrapped_cookie->real_cookie);
+  InternalFree(wrapped_cookie);
+  return res;
+}
+
+INTERCEPTOR(__sanitizer_FILE *, funopen, void *cookie, funopen_readfn readfn,
+funopen_writefn writefn, funopen_seekfn seekfn,
+funopen_closefn closefn) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, funopen, cookie, readfn, writefn, seekfn,
+   closefn);
+
+  WrappedFunopenCookie *wrapped_cookie =
+  (WrappedFunopenCookie *)InternalAlloc(sizeof(WrappedFunopenCookie));
+  wrapped_cookie->real_cookie = cookie;
+  wrapped_cookie->real_read = readfn;
+  wrapped_cookie->real_write = writefn;
+  wrapped_cookie->real_seek = seekfn;
+  wrapped_cookie->real_close = closefn;
+
+  __sanitizer_FILE *res =
+  REAL(funopen)(wrapped_cookie,
+readfn  ? wrapped_funopen_read  : nullptr,
+writefn ? wrapped_funopen_write : nullptr,
+seekfn  ? wrapped_funopen_seek  : nullptr,
+closefn ? wrapped_funopen_close : nullptr);
+  if (res)
+unpoison_file(res);
+  return res;
+}
+#define INIT_FUNOPEN COMMON_INTERCEPT_FUNCTION(funopen)
+#else
+#define INIT_FUNOPEN
+#endif
+
+#if SANITIZER_INTERCEPT_FUNOPEN2
+typedef SSIZE_T (*funopen2_readfn)(void *cookie, void *buf, SIZE_T len);
+typedef SSIZE_T (*funopen2_writefn)(void *cookie, const void *buf, SIZE_T len);
+typedef OFF_T (*funopen2_seekfn)(void *cookie, OFF_T offset, int whence);
+typedef int (*funopen2_flushfn)(void *cookie);
+typedef int (*funopen2_closefn)(void *cookie);
+
+struct WrappedFunopen2Cookie {
+  void *real_cookie;
+  funopen2_readfn real_read;
+  funopen2_writefn real_write;
+  funopen2_seekfn real_seek;
+  funopen2_flushfn real_flush;
+  funopen2_closefn real_close;
+};
+
+static SSIZE_T wrapped_funopen2_read(void *cookie, void *buf, SIZE_T len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedFunopen2Cookie *wrapped_cookie = (WrappedFunopen2Cookie *)cookie;
+  funopen2_readfn real_read = wrapped_cookie->real_read;
+  return real_read(wrapped_cookie->real_cookie, buf, len);
+}
+
+static SSIZE_T wrapped_funopen2_write(void *cookie, const void *buf,
+   

[PATCH] D56157: [sanitizer_common] Implement popen, popenve, pclose interceptors

2019-01-02 Thread Michał Górny via Phabricator via cfe-commits
mgorny marked 4 inline comments as done.
mgorny added a comment.

The tests were submitted earlier as D56153 . 
I'll implement the remaining suggestions.


Repository:
  rCRT Compiler Runtime

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

https://reviews.llvm.org/D56157



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56157: [sanitizer_common] Implement popen, popenve, pclose interceptors

2019-01-02 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179842.
mgorny added a comment.

Updated to use `COMMON_INTERCEPTOR_FILE_OPEN` with `nullptr` argument.


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

https://reviews.llvm.org/D56157

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_interceptors.h
  lib/tsan/rtl/tsan_interceptors.cc

Index: lib/tsan/rtl/tsan_interceptors.cc
===
--- lib/tsan/rtl/tsan_interceptors.cc
+++ lib/tsan/rtl/tsan_interceptors.cc
@@ -2250,7 +2250,8 @@
   (void) ctx;
 
 #define COMMON_INTERCEPTOR_FILE_OPEN(ctx, file, path) \
-  Acquire(thr, pc, File2addr(path));  \
+  if (path)   \
+Acquire(thr, pc, File2addr(path));\
   if (file) { \
 int fd = fileno_unlocked(file);   \
 if (fd >= 0) FdFileCreate(thr, pc, fd);   \
Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -546,4 +546,8 @@
 #define SANITIZER_INTERCEPT_CDB SI_NETBSD
 #define SANITIZER_INTERCEPT_VIS (SI_NETBSD || SI_FREEBSD)
 
+#define SANITIZER_INTERCEPT_POPEN SI_POSIX
+#define SANITIZER_INTERCEPT_POPENVE SI_NETBSD
+#define SANITIZER_INTERCEPT_PCLOSE SI_POSIX
+
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -9058,6 +9058,77 @@
 #define INIT_CDB
 #endif
 
+#if SANITIZER_INTERCEPT_POPEN
+INTERCEPTOR(__sanitizer_FILE *, popen, const char *command, const char *type) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, popen, command, type);
+  if (command)
+COMMON_INTERCEPTOR_READ_RANGE(ctx, command, REAL(strlen)(command) + 1);
+  if (type)
+COMMON_INTERCEPTOR_READ_RANGE(ctx, type, REAL(strlen)(type) + 1);
+  __sanitizer_FILE *res = REAL(popen)(command, type);
+  COMMON_INTERCEPTOR_FILE_OPEN(ctx, res, nullptr);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_POPEN COMMON_INTERCEPT_FUNCTION(popen)
+#else
+#define INIT_POPEN
+#endif
+
+#if SANITIZER_INTERCEPT_POPENVE
+INTERCEPTOR(__sanitizer_FILE *, popenve, const char *path,
+char *const *argv, char *const *envp, const char *type) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, popenve, path, argv, envp, type);
+  if (path)
+COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1);
+  if (argv) {
+for (char *const *pa = argv; ; ++pa) {
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, pa, sizeof(char **));
+  if (!*pa)
+break;
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, *pa, REAL(strlen)(*pa) + 1);
+}
+  }
+  if (envp) {
+for (char *const *pa = envp; ; ++pa) {
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, pa, sizeof(char **));
+  if (!*pa)
+break;
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, *pa, REAL(strlen)(*pa) + 1);
+}
+  }
+  if (type)
+COMMON_INTERCEPTOR_READ_RANGE(ctx, type, REAL(strlen)(type) + 1);
+  __sanitizer_FILE *res = REAL(popenve)(path, argv, envp, type);
+  COMMON_INTERCEPTOR_FILE_OPEN(ctx, res, nullptr);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_POPENVE COMMON_INTERCEPT_FUNCTION(popenve)
+#else
+#define INIT_POPENVE
+#endif
+
+#if SANITIZER_INTERCEPT_PCLOSE
+INTERCEPTOR(int, pclose, __sanitizer_FILE *fp) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, pclose, fp);
+  COMMON_INTERCEPTOR_FILE_CLOSE(ctx, fp);
+  const FileMetadata *m = GetInterceptorMetadata(fp);
+  int res = REAL(pclose)(fp);
+  if (m) {
+COMMON_INTERCEPTOR_INITIALIZE_RANGE(*m->addr, *m->size);
+DeleteInterceptorMetadata(fp);
+  }
+  return res;
+}
+#define INIT_PCLOSE COMMON_INTERCEPT_FUNCTION(pclose);
+#else
+#define INIT_PCLOSE
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
   interceptor_metadata_map =
@@ -9338,6 +9409,9 @@
   INIT_SHA2;
   INIT_VIS;
   INIT_CDB;
+  INIT_POPEN;
+  INIT_POPENVE;
+  INIT_PCLOSE;
 
   INIT___PRINTF_CHK;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56157: [sanitizer_common] Implement popen, popenve, pclose interceptors

2019-01-02 Thread Michał Górny via Phabricator via cfe-commits
mgorny marked an inline comment as done.
mgorny added inline comments.



Comment at: lib/esan/esan_interceptors.cpp:90
   } while (false)
+#define COMMON_INTERCEPTOR_PIPE_OPEN(ctx, file)
\
+  do { 
\

krytarowski wrote:
> dvyukov wrote:
> > The idea behind defining a no-op version in 
> > sanitizer_common_interceptors.inc was exactly that tools that are not 
> > interested in it does not need to be changed. So please remove this.
> I would add an intermediate revision to drop redefinitions in this file.
@krytarowski, apparently it's not that simple. I've tried removing all the 
empty definitions and now I get a lot of build errors ;-). It would probably be 
necessary to take them one by one to establish which one are unnecessary after 
all, and I don't think we have time for this right now.


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

https://reviews.llvm.org/D56157



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56136: [compiler-rt] [sanitizer_common] Add tests for more stdio.h functions

2019-01-02 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL350225: [sanitizer_common] Add tests for more stdio.h 
functions (authored by mgorny, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D56136?vs=179691&id=179865#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D56136

Files:
  compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
  compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc


Index: 
compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
===
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
@@ -0,0 +1,19 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(fgetc(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() worked
+  assert(getc(fp) == 'X');
+
+  assert(!fclose(fp));
+  return 0;
+}
Index: 
compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
===
--- 
compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
+++ 
compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
@@ -0,0 +1,41 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // file should be good upon opening
+  assert(!feof(fp) && !ferror(fp));
+
+  // read until EOF
+  char buf[BUFSIZ];
+  while (fread(buf, 1, sizeof buf, fp) != 0) {}
+  assert(feof(fp));
+
+  // clear EOF
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  // get file descriptor
+  int fd = fileno(fp);
+  assert(fd != -1);
+
+  // break the file by closing underlying descriptor
+  assert(close(fd) != -1);
+
+  // verify that an error is signalled
+  assert(fread(buf, 1, sizeof buf, fp) == 0);
+  assert(ferror(fp));
+
+  // clear error
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  // fclose() will return EBADF because of closed fd
+  assert(fclose(fp) == -1);
+  return 0;
+}


Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
===
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
@@ -0,0 +1,19 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(fgetc(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() worked
+  assert(getc(fp) == 'X');
+
+  assert(!fclose(fp));
+  return 0;
+}
Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
===
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
@@ -0,0 +1,41 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // file should be good upon opening
+  assert(!feof(fp) && !ferror(fp));
+
+  // read until EOF
+  char buf[BUFSIZ];
+  while (fread(buf, 1, sizeof buf, fp) != 0) {}
+  assert(feof(fp));
+
+  // clear EOF
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  // get file descriptor
+  int fd = fileno(fp);
+  assert(fd != -1);
+
+  // break the file by closing underlying descriptor
+  assert(close(fd) != -1);
+
+  // verify that an error is signalled
+  assert(fread(buf, 1, sizeof buf, fp) == 0);
+  assert(ferror(fp));
+
+  // clear error
+  clearerr(fp);
+  assert(!feof(fp) && !ferror(fp));
+
+  // fclose() will return EBADF because of closed fd
+  assert(fclose(fp) == -1);
+  return 0;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56149: [sanitizer_common] Rewrite more Posix tests to use asserts

2019-01-02 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL350227: [sanitizer_common] Rewrite more Posix tests to use 
asserts (authored by mgorny, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D56149?vs=179693&id=179867#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D56149

Files:
  compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/devname.cc
  compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/devname_r.cc
  compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fgetln.cc
  compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fgets.cc
  compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fputs_puts.cc
  compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/lstat.cc

Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/devname.cc
===
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/devname.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/devname.cc
@@ -1,6 +1,7 @@
 // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
 // UNSUPPORTED: linux, solaris
 
+#include 
 #include 
 #include 
 #include 
@@ -9,11 +10,8 @@
   struct stat st;
   char *name;
 
-  if (stat("/dev/null", &st))
-exit(1);
-
-  if (!(name = devname(st.st_rdev, S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK)))
-exit(1);
+  assert(!stat("/dev/null", &st));
+  assert((name = devname(st.st_rdev, S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK)));
 
   printf("%s\n", name);
 
Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fputs_puts.cc
===
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fputs_puts.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fputs_puts.cc
@@ -1,18 +1,12 @@
 // RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
 // CHECK: {{^foobar$}}
 
+#include 
 #include 
 
 int main(void) {
-  int r;
-
-  r = fputs("foo", stdout);
-  if (r < 0)
-return 1;
-
-  r = puts("bar");
-  if (r < 0)
-return 1;
+  assert(fputs("foo", stdout) >= 0);
+  assert(puts("bar") >= 0);
 
   return 0;
 }
Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fgets.cc
===
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fgets.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fgets.cc
@@ -1,20 +1,16 @@
 // RUN: %clangxx -g %s -o %t && %run %t
 
+#include 
 #include 
 
 int main(int argc, char **argv) {
-  FILE *fp;
-  char buf[2];
-  char *s;
-
-  fp = fopen(argv[0], "r");
-  if (!fp)
-return 1;
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
 
-  s = fgets(buf, sizeof(buf), fp);
-  if (!s)
-return 2;
+  char buf[2];
+  char *s = fgets(buf, sizeof(buf), fp);
+  assert(s);
 
-  fclose(fp);
+  assert(!fclose(fp));
   return 0;
 }
Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fgetln.cc
===
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fgetln.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fgetln.cc
@@ -1,24 +1,20 @@
 // RUN: %clangxx -O0 -g %s -o %t && %run %t
 // UNSUPPORTED: linux
 
+#include 
 #include 
 #include 
 
 int main(void) {
-  FILE *fp;
-  size_t len;
-  char *s;
-
-  fp = fopen("/etc/hosts", "r");
-  if (!fp)
-exit(1);
+  FILE *fp = fopen("/etc/hosts", "r");
+  assert(fp);
 
-  s = fgetln(fp, &len);
+  size_t len;
+  char *s = fgetln(fp, &len);
 
   printf("%.*s\n", (int)len, s);
 
-  if (fclose(fp) == EOF)
-exit(1);
+  assert(!fclose(fp));
 
   return 0;
 }
Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/devname_r.cc
===
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/devname_r.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/devname_r.cc
@@ -4,6 +4,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 
@@ -12,17 +13,14 @@
   char name[100];
   mode_t type;
 
-  if (stat("/dev/null", &st))
-exit(1);
+  assert(!stat("/dev/null", &st));
 
   type = S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK;
 
 #if defined(__NetBSD__)
-  if (devname_r(st.st_rdev, type, name, sizeof(name)))
-exit(1);
+  assert(!devname_r(st.st_rdev, type, name, sizeof(name)));
 #else
-  if (!devname_r(st.st_rdev, type, name, sizeof(name)))
-exit(1);
+  assert(devname_r(st.st_rdev, type, name, sizeof(name)));
 #endif
 
   printf("%s\n", name);
Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/lstat.cc
===
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/lstat.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/lstat.cc
@@ -1,16 +1,14 @@
 // RUN: %clan

[PATCH] D56150: [sanitizer_common] Fix devname_r() return type on !NetBSD

2019-01-02 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL350228: [sanitizer_common] Fix devname_r() return type on 
!NetBSD (authored by mgorny, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D56150?vs=179707&id=179869#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D56150

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc


Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7061,12 +7061,19 @@
 #endif
 
 #if SANITIZER_INTERCEPT_DEVNAME_R
-INTERCEPTOR(int, devname_r, u64 dev, u32 type, char *path, uptr len) {
+#if SANITIZER_NETBSD
+#define DEVNAME_R_RETTYPE int
+#define DEVNAME_R_SUCCESS(x) (!(x))
+#else
+#define DEVNAME_R_RETTYPE char*
+#define DEVNAME_R_SUCCESS(x) (x)
+#endif
+INTERCEPTOR(DEVNAME_R_RETTYPE, devname_r, u64 dev, u32 type, char *path,
+uptr len) {
   void *ctx;
-  int res;
   COMMON_INTERCEPTOR_ENTER(ctx, devname_r, dev, type, path, len);
-  res = REAL(devname_r)(dev, type, path, len);
-  if (!res)
+  DEVNAME_R_RETTYPE res = REAL(devname_r)(dev, type, path, len);
+  if (DEVNAME_R_SUCCESS(res))
 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, path, REAL(strlen)(path) + 1);
   return res;
 }


Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7061,12 +7061,19 @@
 #endif
 
 #if SANITIZER_INTERCEPT_DEVNAME_R
-INTERCEPTOR(int, devname_r, u64 dev, u32 type, char *path, uptr len) {
+#if SANITIZER_NETBSD
+#define DEVNAME_R_RETTYPE int
+#define DEVNAME_R_SUCCESS(x) (!(x))
+#else
+#define DEVNAME_R_RETTYPE char*
+#define DEVNAME_R_SUCCESS(x) (x)
+#endif
+INTERCEPTOR(DEVNAME_R_RETTYPE, devname_r, u64 dev, u32 type, char *path,
+uptr len) {
   void *ctx;
-  int res;
   COMMON_INTERCEPTOR_ENTER(ctx, devname_r, dev, type, path, len);
-  res = REAL(devname_r)(dev, type, path, len);
-  if (!res)
+  DEVNAME_R_RETTYPE res = REAL(devname_r)(dev, type, path, len);
+  if (DEVNAME_R_SUCCESS(res))
 COMMON_INTERCEPTOR_WRITE_RANGE(ctx, path, REAL(strlen)(path) + 1);
   return res;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56152: [sanitizer_common] Add tests for more *putc and *getc variants

2019-01-02 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL350229: [sanitizer_common] Add tests for more *putc and 
*getc variants (authored by mgorny, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D56152?vs=179711&id=179868#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D56152

Files:
  compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
  compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
  
compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc


Index: 
compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
===
--- 
compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
+++ 
compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
@@ -0,0 +1,13 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: abc
+
+#include 
+#include 
+
+int main(void) {
+  assert(fputc('a', stdout) != EOF);
+  assert(putc('b', stdout) != EOF);
+  assert(putchar('c') != EOF);
+
+  return 0;
+}
Index: 
compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
===
--- 
compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
+++ 
compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
@@ -0,0 +1,12 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: bc
+
+#include 
+#include 
+
+int main(void) {
+  assert(putc_unlocked('b', stdout) != EOF);
+  assert(putchar_unlocked('c') != EOF);
+
+  return 0;
+}
Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
===
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
@@ -0,0 +1,20 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(getc_unlocked(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  // NB: ungetc_unlocked is apparently not present
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() works with getc_unlocked()
+  assert(getc_unlocked(fp) == 'X');
+
+  assert(!fclose(fp));
+  return 0;
+}


Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
===
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc
@@ -0,0 +1,13 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: abc
+
+#include 
+#include 
+
+int main(void) {
+  assert(fputc('a', stdout) != EOF);
+  assert(putc('b', stdout) != EOF);
+  assert(putchar('c') != EOF);
+
+  return 0;
+}
Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
===
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc
@@ -0,0 +1,12 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: bc
+
+#include 
+#include 
+
+int main(void) {
+  assert(putc_unlocked('b', stdout) != EOF);
+  assert(putchar_unlocked('c') != EOF);
+
+  return 0;
+}
Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
===
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getc_unlocked.cc
@@ -0,0 +1,20 @@
+// RUN: %clangxx -g %s -o %t && %run %t
+
+#include 
+#include 
+
+int main(int argc, char **argv) {
+  FILE *fp = fopen(argv[0], "r");
+  assert(fp);
+
+  // the file should be at least one character long, always
+  assert(getc_unlocked(fp) != EOF);
+  // POSIX guarantees being able to ungetc() at least one character
+  // NB: ungetc_unlocked is apparently not present
+  assert(ungetc('X', fp) != EOF);
+  // check whether ungetc() works with getc_unlocked()
+  assert(getc_unlocked(fp) == 'X');
+
+  assert(!fclose(fp));
+  return 0;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56153: [sanitizer_common] Add test for popen()

2019-01-02 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL350230: [sanitizer_common] Add test for popen() (authored by 
mgorny, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D56153?vs=179712&id=179870#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D56153

Files:
  compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/popen.cc


Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/popen.cc
===
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/popen.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/popen.cc
@@ -0,0 +1,23 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: 1
+// CHECK-NEXT: 2
+
+#include 
+#include 
+
+int main(void) {
+  // use a tool that produces different output than input to verify
+  // that everything worked correctly
+  FILE *fp = popen("sort", "w");
+  assert(fp);
+
+  // verify that fileno() returns a meaningful descriptor (needed
+  // for the implementation of TSan)
+  assert(fileno(fp) != -1);
+
+  assert(fputs("2\n", fp) >= 0);
+  assert(fputs("1\n", fp) >= 0);
+  assert(pclose(fp) == 0);
+
+  return 0;
+}


Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/popen.cc
===
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/popen.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/popen.cc
@@ -0,0 +1,23 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+// CHECK: 1
+// CHECK-NEXT: 2
+
+#include 
+#include 
+
+int main(void) {
+  // use a tool that produces different output than input to verify
+  // that everything worked correctly
+  FILE *fp = popen("sort", "w");
+  assert(fp);
+
+  // verify that fileno() returns a meaningful descriptor (needed
+  // for the implementation of TSan)
+  assert(fileno(fp) != -1);
+
+  assert(fputs("2\n", fp) >= 0);
+  assert(fputs("1\n", fp) >= 0);
+  assert(pclose(fp) == 0);
+
+  return 0;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56154: [sanitizer_common] Add tests for NetBSD funopen*()

2019-01-02 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL350231: [sanitizer_common] Add tests for NetBSD funopen*() 
functions (authored by mgorny, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D56154?vs=179713&id=179871#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D56154

Files:
  compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/funopen.cc
  compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/funopen2.cc

Index: compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/funopen2.cc
===
--- compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/funopen2.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/funopen2.cc
@@ -0,0 +1,110 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+
+// CHECK: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: CLOSE CALLED
+// CHECK-NEXT: SEEK CALLED; off=100, whence=0
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: FLUSH CALLED
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: FLUSH CALLED
+
+#include 
+#include 
+#include 
+#include 
+
+int cookie_var;
+
+ssize_t f_read(void *cookie, void *buf, size_t len) {
+  assert(cookie == &cookie_var);
+  assert(len >= 6);
+  printf("READ CALLED; len=%zd\n", len);
+  return strlcpy((char*)buf, "test\n", len);
+}
+
+ssize_t f_write(void *cookie, const void *buf, size_t len) {
+  assert(cookie == &cookie_var);
+  char *data = strndup((char*)buf, len);
+  assert(data);
+  printf("WRITE CALLED: %s\n", data);
+  free(data);
+  return len;
+}
+
+off_t f_seek(void *cookie, off_t off, int whence) {
+  assert(cookie == &cookie_var);
+  assert(whence == SEEK_SET);
+  printf("SEEK CALLED; off=%d, whence=%d\n", (int)off, whence);
+  return off;
+}
+
+int f_flush(void *cookie) {
+  assert(cookie == &cookie_var);
+  printf("FLUSH CALLED\n");
+  return 0;
+}
+
+int f_close(void *cookie) {
+  assert(cookie == &cookie_var);
+  printf("CLOSE CALLED\n");
+  return 0;
+}
+
+int main(void) {
+  FILE *fp;
+  char buf[10];
+
+  // 1. read-only variant
+  fp = fropen2(&cookie_var, f_read);
+  assert(fp);
+  // verify that fileno() does not crash or report nonsense
+  assert(fileno(fp) == -1);
+  assert(fgets(buf, sizeof(buf), fp));
+  printf("READ: %s", buf);
+  assert(!fclose(fp));
+
+  // 2. write-only variant
+  fp = fwopen2(&cookie_var, f_write);
+  assert(fp);
+  assert(fileno(fp) == -1);
+  assert(fputs("test", fp) >= 0);
+  assert(!fclose(fp));
+
+  // 3. read+write+close
+  fp = funopen2(&cookie_var, f_read, f_write, NULL, NULL, f_close);
+  assert(fp);
+  assert(fileno(fp) == -1);
+  assert(fgets(buf, sizeof(buf), fp));
+  printf("READ: %s", buf);
+  assert(fputs("test", fp) >= 0);
+  assert(!fflush(fp));
+  assert(!fclose(fp));
+
+  // 4. read+seek
+  fp = funopen2(&cookie_var, f_read, NULL, f_seek, NULL, NULL);
+  assert(fp);
+  assert(fileno(fp) == -1);
+  assert(fseek(fp, 100, SEEK_SET) == 0);
+  assert(fgets(buf, sizeof(buf), fp));
+  printf("READ: %s", buf);
+  assert(!fclose(fp));
+
+  // 5. write+flush
+  fp = funopen2(&cookie_var, NULL, f_write, NULL, f_flush, NULL);
+  assert(fp);
+  assert(fileno(fp) == -1);
+  assert(fputs("test", fp) >= 0);
+  assert(!fflush(fp));
+  assert(fputs("test", fp) >= 0);
+  // NB: fclose() also implicitly calls flush
+  assert(!fclose(fp));
+
+  return 0;
+}
Index: compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/funopen.cc
===
--- compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/funopen.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/funopen.cc
@@ -0,0 +1,89 @@
+// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
+
+// CHECK: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+// CHECK-NEXT: WRITE CALLED: test
+// CHECK-NEXT: CLOSE CALLED
+// CHECK-NEXT: SEEK CALLED; off=100, whence=0
+// CHECK-NEXT: READ CALLED; len={{[0-9]*}}
+// CHECK-NEXT: READ: test
+
+#include 
+#include 
+#include 
+#include 
+
+int cookie_var;
+
+int f_read(void *cookie, char *buf, int len) {
+  assert(cookie == &cookie_var);
+  assert(len >= 6);
+  printf("READ CALLED; len=%d\n", len);
+  return strlcpy(buf, "test\n", len);
+}
+
+int f_write(void *cookie, const char *buf, int len) {
+  assert(cookie == &cookie_var);
+  char *data = strndup(buf, len);
+  assert(data);
+  printf("WRITE CALLED: %s\n", data);
+  free(data);
+  return len;
+}
+
+off_t f_seek(void *cookie, off_t off, int whence) {
+  assert(cookie == &cookie_var);
+  as

[PATCH] D56158: [sanitizer_common] Implement funopen*() interceptors for NetBSD

2019-01-02 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL350233: [sanitizer_common] Implement funopen*() interceptors 
for NetBSD (authored by mgorny, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D56158?vs=179728&id=179873#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D56158

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h

Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -551,5 +551,7 @@
 #define SANITIZER_INTERCEPT_POPEN SI_POSIX
 #define SANITIZER_INTERCEPT_POPENVE SI_NETBSD
 #define SANITIZER_INTERCEPT_PCLOSE SI_POSIX
+#define SANITIZER_INTERCEPT_FUNOPEN SI_NETBSD
+#define SANITIZER_INTERCEPT_FUNOPEN2 SI_NETBSD
 
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -9187,6 +9187,166 @@
 #define INIT_PCLOSE
 #endif
 
+#if SANITIZER_INTERCEPT_FUNOPEN
+typedef int (*funopen_readfn)(void *cookie, char *buf, int len);
+typedef int (*funopen_writefn)(void *cookie, const char *buf, int len);
+typedef OFF_T (*funopen_seekfn)(void *cookie, OFF_T offset, int whence);
+typedef int (*funopen_closefn)(void *cookie);
+
+struct WrappedFunopenCookie {
+  void *real_cookie;
+  funopen_readfn real_read;
+  funopen_writefn real_write;
+  funopen_seekfn real_seek;
+  funopen_closefn real_close;
+};
+
+static int wrapped_funopen_read(void *cookie, char *buf, int len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedFunopenCookie *wrapped_cookie = (WrappedFunopenCookie *)cookie;
+  funopen_readfn real_read = wrapped_cookie->real_read;
+  return real_read(wrapped_cookie->real_cookie, buf, len);
+}
+
+static int wrapped_funopen_write(void *cookie, const char *buf, int len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedFunopenCookie *wrapped_cookie = (WrappedFunopenCookie *)cookie;
+  funopen_writefn real_write = wrapped_cookie->real_write;
+  return real_write(wrapped_cookie->real_cookie, buf, len);
+}
+
+static OFF_T wrapped_funopen_seek(void *cookie, OFF_T offset, int whence) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedFunopenCookie *wrapped_cookie = (WrappedFunopenCookie *)cookie;
+  funopen_seekfn real_seek = wrapped_cookie->real_seek;
+  return real_seek(wrapped_cookie->real_cookie, offset, whence);
+}
+
+static int wrapped_funopen_close(void *cookie) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(1);
+  WrappedFunopenCookie *wrapped_cookie = (WrappedFunopenCookie *)cookie;
+  funopen_closefn real_close = wrapped_cookie->real_close;
+  int res = real_close(wrapped_cookie->real_cookie);
+  InternalFree(wrapped_cookie);
+  return res;
+}
+
+INTERCEPTOR(__sanitizer_FILE *, funopen, void *cookie, funopen_readfn readfn,
+funopen_writefn writefn, funopen_seekfn seekfn,
+funopen_closefn closefn) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, funopen, cookie, readfn, writefn, seekfn,
+   closefn);
+
+  WrappedFunopenCookie *wrapped_cookie =
+  (WrappedFunopenCookie *)InternalAlloc(sizeof(WrappedFunopenCookie));
+  wrapped_cookie->real_cookie = cookie;
+  wrapped_cookie->real_read = readfn;
+  wrapped_cookie->real_write = writefn;
+  wrapped_cookie->real_seek = seekfn;
+  wrapped_cookie->real_close = closefn;
+
+  __sanitizer_FILE *res =
+  REAL(funopen)(wrapped_cookie,
+readfn  ? wrapped_funopen_read  : nullptr,
+writefn ? wrapped_funopen_write : nullptr,
+seekfn  ? wrapped_funopen_seek  : nullptr,
+closefn ? wrapped_funopen_close : nullptr);
+  if (res)
+unpoison_file(res);
+  return res;
+}
+#define INIT_FUNOPEN COMMON_INTERCEPT_FUNCTION(funopen)
+#else
+#define INIT_FUNOPEN
+#endif
+
+#if SANITIZER_INTERCEPT_FUNOPEN2
+typedef SSIZE_T (*funopen2_readfn)(void *cookie, void *buf, SIZE_T len);
+typedef SSIZE_T (*funopen2_writefn)(void *cookie, const void *buf, SIZE_T len);
+typedef OFF_T (*funopen2_seekfn)(void *cookie, OFF_T offset, int whence);
+typedef int (*funopen2_flushfn)(void *cookie);
+typedef int (*funopen2_closefn)(void *cookie);
+
+struct WrappedFunopen2Cookie {
+  void *real_cookie;
+  funopen2_readfn real_read;
+  funopen2_writefn real_write;
+  funopen2_seekfn real_seek;
+  funopen2_flushfn real_flush;
+  funopen2_closefn real_close;
+};

[PATCH] D56157: [sanitizer_common] Implement popen, popenve, pclose interceptors

2019-01-02 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL350232: [sanitizer_common] Implement popen, popenve, pclose 
interceptors (authored by mgorny, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D56157?vs=179842&id=179872#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D56157

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
  compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc

Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -548,4 +548,8 @@
 #define SANITIZER_INTERCEPT_GETFSENT (SI_FREEBSD || SI_NETBSD || SI_MAC)
 #define SANITIZER_INTERCEPT_ARC4RANDOM (SI_FREEBSD || SI_NETBSD)
 
+#define SANITIZER_INTERCEPT_POPEN SI_POSIX
+#define SANITIZER_INTERCEPT_POPENVE SI_NETBSD
+#define SANITIZER_INTERCEPT_PCLOSE SI_POSIX
+
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -9116,6 +9116,77 @@
 #define INIT_ARC4RANDOM
 #endif
 
+#if SANITIZER_INTERCEPT_POPEN
+INTERCEPTOR(__sanitizer_FILE *, popen, const char *command, const char *type) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, popen, command, type);
+  if (command)
+COMMON_INTERCEPTOR_READ_RANGE(ctx, command, REAL(strlen)(command) + 1);
+  if (type)
+COMMON_INTERCEPTOR_READ_RANGE(ctx, type, REAL(strlen)(type) + 1);
+  __sanitizer_FILE *res = REAL(popen)(command, type);
+  COMMON_INTERCEPTOR_FILE_OPEN(ctx, res, nullptr);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_POPEN COMMON_INTERCEPT_FUNCTION(popen)
+#else
+#define INIT_POPEN
+#endif
+
+#if SANITIZER_INTERCEPT_POPENVE
+INTERCEPTOR(__sanitizer_FILE *, popenve, const char *path,
+char *const *argv, char *const *envp, const char *type) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, popenve, path, argv, envp, type);
+  if (path)
+COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1);
+  if (argv) {
+for (char *const *pa = argv; ; ++pa) {
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, pa, sizeof(char **));
+  if (!*pa)
+break;
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, *pa, REAL(strlen)(*pa) + 1);
+}
+  }
+  if (envp) {
+for (char *const *pa = envp; ; ++pa) {
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, pa, sizeof(char **));
+  if (!*pa)
+break;
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, *pa, REAL(strlen)(*pa) + 1);
+}
+  }
+  if (type)
+COMMON_INTERCEPTOR_READ_RANGE(ctx, type, REAL(strlen)(type) + 1);
+  __sanitizer_FILE *res = REAL(popenve)(path, argv, envp, type);
+  COMMON_INTERCEPTOR_FILE_OPEN(ctx, res, nullptr);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_POPENVE COMMON_INTERCEPT_FUNCTION(popenve)
+#else
+#define INIT_POPENVE
+#endif
+
+#if SANITIZER_INTERCEPT_PCLOSE
+INTERCEPTOR(int, pclose, __sanitizer_FILE *fp) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, pclose, fp);
+  COMMON_INTERCEPTOR_FILE_CLOSE(ctx, fp);
+  const FileMetadata *m = GetInterceptorMetadata(fp);
+  int res = REAL(pclose)(fp);
+  if (m) {
+COMMON_INTERCEPTOR_INITIALIZE_RANGE(*m->addr, *m->size);
+DeleteInterceptorMetadata(fp);
+  }
+  return res;
+}
+#define INIT_PCLOSE COMMON_INTERCEPT_FUNCTION(pclose);
+#else
+#define INIT_PCLOSE
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
   interceptor_metadata_map =
@@ -9398,6 +9469,9 @@
   INIT_CDB;
   INIT_GETFSENT;
   INIT_ARC4RANDOM;
+  INIT_POPEN;
+  INIT_POPENVE;
+  INIT_PCLOSE;
 
   INIT___PRINTF_CHK;
 }
Index: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
===
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
@@ -2254,7 +2254,8 @@
   (void) ctx;
 
 #define COMMON_INTERCEPTOR_FILE_OPEN(ctx, file, path) \
-  Acquire(thr, pc, File2addr(path));  \
+  if (path)   \
+Acquire(thr, pc, File2addr(path));\
   if (file) { \
 int fd = fileno_unlocked(file);   \
 if (fd >= 0) FdFileCreate(thr, pc, fd);   \
___
cfe-commits mailing list
cfe-commits@lists.

[PATCH] D56215: [lld] [ELF] Include default search paths for NetBSD driver

2019-01-02 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, joerg, ruiu, grimar, espindola.
mgorny added a project: lld.
Herald added subscribers: llvm-commits, MaskRay, arichardson, emaste.

The NetBSD clang driver relies on NetBSD ld knowing the default search
paths and never passes those paths explicitly.  As a result of this
design requirement, implement appending default search paths within lld
as well.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D56215

Files:
  ELF/Driver.cpp
  ELF/Driver.h


Index: ELF/Driver.h
===
--- ELF/Driver.h
+++ ELF/Driver.h
@@ -32,6 +32,7 @@
 
 private:
   void readConfigs(llvm::opt::InputArgList &Args);
+  void appendDefaultSearchPaths();
   void createFiles(llvm::opt::InputArgList &Args);
   void inferMachineType();
   template  void link(llvm::opt::InputArgList &Args);
Index: ELF/Driver.cpp
===
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -365,6 +365,15 @@
   error("unknown -z value: " + StringRef(Arg->getValue()));
 }
 
+void LinkerDriver::appendDefaultSearchPaths() {
+#if defined(__NetBSD__)
+  // NetBSD driver relies on the linker knowing the default search paths.
+  Config->SearchPaths.push_back("/usr/local/lib");
+  Config->SearchPaths.push_back("/lib");
+  Config->SearchPaths.push_back("/usr/lib");
+#endif
+}
+
 void LinkerDriver::main(ArrayRef ArgsArr) {
   ELFOptTable Parser;
   opt::InputArgList Args = Parser.parse(ArgsArr.slice(1));
@@ -412,6 +421,7 @@
 
   readConfigs(Args);
   checkZOptions(Args);
+  appendDefaultSearchPaths();
 
   // The behavior of -v or --version is a bit strange, but this is
   // needed for compatibility with GNU linkers.


Index: ELF/Driver.h
===
--- ELF/Driver.h
+++ ELF/Driver.h
@@ -32,6 +32,7 @@
 
 private:
   void readConfigs(llvm::opt::InputArgList &Args);
+  void appendDefaultSearchPaths();
   void createFiles(llvm::opt::InputArgList &Args);
   void inferMachineType();
   template  void link(llvm::opt::InputArgList &Args);
Index: ELF/Driver.cpp
===
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -365,6 +365,15 @@
   error("unknown -z value: " + StringRef(Arg->getValue()));
 }
 
+void LinkerDriver::appendDefaultSearchPaths() {
+#if defined(__NetBSD__)
+  // NetBSD driver relies on the linker knowing the default search paths.
+  Config->SearchPaths.push_back("/usr/local/lib");
+  Config->SearchPaths.push_back("/lib");
+  Config->SearchPaths.push_back("/usr/lib");
+#endif
+}
+
 void LinkerDriver::main(ArrayRef ArgsArr) {
   ELFOptTable Parser;
   opt::InputArgList Args = Parser.parse(ArgsArr.slice(1));
@@ -412,6 +421,7 @@
 
   readConfigs(Args);
   checkZOptions(Args);
+  appendDefaultSearchPaths();
 
   // The behavior of -v or --version is a bit strange, but this is
   // needed for compatibility with GNU linkers.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56061: [clang-tools-extra] [clangd] Fix detecting atomics in stand-alone builds

2019-01-03 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE350329: [clangd] Fix detecting atomics in stand-alone 
builds (authored by mgorny, committed by ).

Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D56061

Files:
  clangd/CMakeLists.txt


Index: clangd/CMakeLists.txt
===
--- clangd/CMakeLists.txt
+++ clangd/CMakeLists.txt
@@ -2,6 +2,11 @@
   Support
   )
 
+if(CLANG_BUILT_STANDALONE)
+  # needed to get HAVE_CXX_ATOMICS64_WITHOUT_LIB defined
+  include(CheckAtomic)
+endif()
+
 set(CLANGD_ATOMIC_LIB "")
 if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
   list(APPEND CLANGD_ATOMIC_LIB "atomic")


Index: clangd/CMakeLists.txt
===
--- clangd/CMakeLists.txt
+++ clangd/CMakeLists.txt
@@ -2,6 +2,11 @@
   Support
   )
 
+if(CLANG_BUILT_STANDALONE)
+  # needed to get HAVE_CXX_ATOMICS64_WITHOUT_LIB defined
+  include(CheckAtomic)
+endif()
+
 set(CLANGD_ATOMIC_LIB "")
 if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
   list(APPEND CLANGD_ATOMIC_LIB "atomic")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


<    1   2   3   4   5   6   7   8   9   >