Skip to content

Commit

Permalink
Revert msan patch (#4788)
Browse files Browse the repository at this point in the history
* Revert "Fix msan build breakage. (#4787)"

This reverts commit 8f4d1b2.

* Revert "Clean up MemorySanitizer library warnings (#4694)"

This reverts commit 6fc050e.
  • Loading branch information
inferno-chromium authored Dec 5, 2020
1 parent 8f4d1b2 commit b9e6a5f
Show file tree
Hide file tree
Showing 20 changed files with 293 additions and 333 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/infra_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ jobs:
sudo env "PATH=$PATH" pip install -r infra/ci/requirements.txt
sudo env "PATH=$PATH" pip install -r infra/build/functions/requirements.txt
- name: Install python-apt
run: |
git clone https://salsa.debian.org/apt-team/python-apt.git -b 1.6.5ubuntu0.3 --depth 1 /tmp/python-apt
cd /tmp/python-apt
sudo env "PATH=$PATH" apt build-dep ./
sudo env "PATH=$PATH" python setup.py install
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '298.0.0'
Expand Down
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ disable=print-statement,
reduce-builtin,
standarderror-builtin,
unicode-builtin,
xrange-builtin,
coerce-method,
delslice-method,
getslice-method,
Expand Down
2 changes: 0 additions & 2 deletions infra/base-images/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ docker build -t gcr.io/oss-fuzz-base/base-clang "$@" infra/base-images/base-clan
docker build -t gcr.io/oss-fuzz-base/base-builder -t gcr.io/oss-fuzz/base-libfuzzer "$@" infra/base-images/base-builder
docker build -t gcr.io/oss-fuzz-base/base-runner "$@" infra/base-images/base-runner
docker build -t gcr.io/oss-fuzz-base/base-runner-debug "$@" infra/base-images/base-runner-debug
docker build -t gcr.io/oss-fuzz-base/base-sanitizer-libs-builder "$@" infra/base-images/base-sanitizer-libs-builder
docker build -t gcr.io/oss-fuzz-base/msan-libs-builder "$@" infra/base-images/msan-libs-builder
69 changes: 34 additions & 35 deletions infra/base-images/base-sanitizer-libs-builder/compiler_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#
################################################################################
"""Wrapper script to call clang or GCC with modified arguments."""

from __future__ import print_function
import os
import subprocess
Expand All @@ -26,23 +26,23 @@
'-aux-info',
]

M32_BIT_ARGS = [
'-m32',
'-mx32',
]


def invoked_as_gcc():
def InvokedAsGcc():
"""Return whether or not we're pretending to be GCC."""
return sys.argv[0].endswith('gcc') or sys.argv[0].endswith('g++')


def is_32_bit(args):
def Is32Bit(args):
"""Return whether or not we're 32-bit."""
M32_BIT_ARGS = [
'-m32',
'-mx32',
]

return any(arg in M32_BIT_ARGS for arg in args)


def filter_wl_arg(arg):
def FilterWlArg(arg):
"""Remove -z,defs and equivalents from a single -Wl option."""
parts = arg.split(',')[1:]

Expand All @@ -55,7 +55,7 @@ def filter_wl_arg(arg):

if part == '--no-undefined':
continue

filtered.append(part)

if filtered:
Expand All @@ -65,29 +65,29 @@ def filter_wl_arg(arg):
return None


def _remove_last_matching(args, find):
for i in range(len(args) - 1, -1, -1):
if args[i] == find:
del args[i]
def _RemoveLastMatching(l, find):
for i in xrange(len(l) - 1, -1, -1):
if l[i] == find:
del l[i]
return

raise IndexError('Not found')


def remove_z_defs(args):
def RemoveZDefs(args):
"""Remove unsupported -Wl,-z,defs linker option."""
filtered = []

for arg in args:
if arg == '-Wl,defs':
_remove_last_matching(filtered, '-Wl,-z')
_RemoveLastMatching(filtered, '-Wl,-z')
continue

if arg == '-Wl,--no-undefined':
continue

if arg.startswith('-Wl,'):
arg = filter_wl_arg(arg)
arg = FilterWlArg(arg)
if not arg:
continue

Expand All @@ -96,11 +96,11 @@ def remove_z_defs(args):
return filtered


def get_compiler_args(args, is_cxx):
def GetCompilerArgs(args, is_cxx):
"""Generate compiler args."""
compiler_args = args[1:]

if is_32_bit(args):
if Is32Bit(args):
# 32 bit builds not supported.
compiler_args.extend([
'-fno-sanitize=memory',
Expand All @@ -109,7 +109,7 @@ def get_compiler_args(args, is_cxx):

return compiler_args

compiler_args = remove_z_defs(compiler_args)
compiler_args = RemoveZDefs(compiler_args)
compiler_args.extend([
# FORTIFY_SOURCE is not supported by sanitizers.
'-U_FORTIFY_SOURCE',
Expand All @@ -122,52 +122,51 @@ def get_compiler_args(args, is_cxx):
'-fno-lto',
])

if invoked_as_gcc():
if InvokedAsGcc():
compiler_args.extend([
# For better compatibility with flags passed via -Wa,...
'-fno-integrated-as',
# For better compatibility with flags passed via -Wa,...
'-fno-integrated-as',
])

if '-fsanitize=memory' not in args:
# If MSan flags weren't added for some reason, add them here.
compiler_args.extend(msan_build.get_injected_flags())
compiler_args.extend(msan_build.GetInjectedFlags())

if is_cxx:
compiler_args.append('-stdlib=libc++')

return compiler_args


def find_real_clang():
def FindRealClang():
"""Return path to real clang."""
return os.environ['REAL_CLANG_PATH']


def fallback_to_gcc(args):
def FallbackToGcc(args):
"""Check whether if we should fall back to GCC."""
if not invoked_as_gcc():
if not InvokedAsGcc():
return False

return any(arg in GCC_ONLY_ARGS for arg in args[1:])


def main(args):
"""Modify arguments and call the real compiler."""
if fallback_to_gcc(args):
sys.exit(
subprocess.call(['/usr/bin/' + os.path.basename(args[0])] + args[1:]))
if FallbackToGcc(args):
sys.exit(subprocess.call(['/usr/bin/' + os.path.basename(args[0])] +
args[1:]))

is_cxx = args[0].endswith('++')
real_clang = find_real_clang()
real_clang = FindRealClang()

if is_cxx:
real_clang += '++'

args = [real_clang] + get_compiler_args(args, is_cxx)
args = [real_clang] + GetCompilerArgs(args, is_cxx)
debug_log_path = os.getenv('WRAPPER_DEBUG_LOG_PATH')
if debug_log_path:
with open(debug_log_path, 'a') as log_file:
log_file.write(str(args) + '\n')
with open(debug_log_path, 'a') as f:
f.write(str(args) + '\n')

sys.exit(subprocess.call(args))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
#!/usr/bin/env python3
# Copyright 2020 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
"""Tests for compiler_wrapper."""

from __future__ import print_function
Expand All @@ -24,41 +8,35 @@


class CompilerWrapperTest(unittest.TestCase):
"""Tests for compiler_wrapper."""

def test_filter_z_defs(self):
"""Reference tests for remove_z_defs."""
self.assertListEqual(['arg'],
compiler_wrapper.remove_z_defs(['arg', '-Wl,-z,defs']))
def testFilterZDefs(self):
self.assertListEqual(
['arg'],
compiler_wrapper.RemoveZDefs(['arg', '-Wl,-z,defs']))

self.assertListEqual(['arg'],
compiler_wrapper.remove_z_defs(
['arg', '-Wl,--no-undefined']))
self.assertListEqual(
['arg'],
compiler_wrapper.RemoveZDefs(['arg', '-Wl,-z,--no-undefined']))

self.assertListEqual(['arg', '-Wl,-z,relro'],
compiler_wrapper.remove_z_defs(['arg',
'-Wl,-z,relro']))
self.assertListEqual(
['arg', '-Wl,-z,relro'],
compiler_wrapper.RemoveZDefs(['arg', '-Wl,-z,relro']))

self.assertListEqual(['arg', '-Wl,-soname,lib.so.1,-z,relro'],
compiler_wrapper.remove_z_defs(
['arg', '-Wl,-soname,lib.so.1,-z,defs,-z,relro']))
self.assertListEqual(
['arg', '-Wl,-soname,lib.so.1,-z,relro'],
compiler_wrapper.RemoveZDefs(['arg', '-Wl,-soname,lib.so.1,-z,defs,-z,relro']))

self.assertListEqual(['arg', '-Wl,-z,relro'],
compiler_wrapper.remove_z_defs(
['arg', '-Wl,-z,relro,-z,defs']))
self.assertListEqual(
['arg', '-Wl,-z,relro'],
compiler_wrapper.RemoveZDefs(['arg', '-Wl,-z,relro,-z,defs']))

self.assertListEqual(['arg'],
compiler_wrapper.remove_z_defs(
['arg', '-Wl,-z', '-Wl,defs']))

self.assertListEqual(['arg', 'arg2'],
compiler_wrapper.remove_z_defs(
['arg', 'arg2', '-Wl,--no-undefined']))

self.assertListEqual(['arg', 'arg2'],
compiler_wrapper.remove_z_defs(
['arg', '-Wl,-z', 'arg2', '-Wl,defs']))
self.assertListEqual(
['arg'],
compiler_wrapper.RemoveZDefs(['arg', '-Wl,-z', '-Wl,defs']))

self.assertListEqual(
['arg', 'arg2'],
compiler_wrapper.RemoveZDefs(['arg', '-Wl,-z', 'arg2', '-Wl,--no-undefined']))

if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit b9e6a5f

Please sign in to comment.