[lsan] Ignore code comments

Code comments are heap-allocated and never freed. We don't want to
attach them to the code object via a finalizer, since that could change
gc timing and heap layout when you enable code comments. They are used
to testing only anyway, so leaking is acceptable here.

R=bmeurer@chromium.org, jarin@chromium.org

Bug: v8:7738
Change-Id: I27b0f95db1d66b57f4f113c154f23edb84e6700d
Reviewed-on: https://chromium-review.googlesource.com/1051241
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53107}
This commit is contained in:
Clemens Hammacher 2018-05-09 11:13:49 +02:00 committed by Commit Bot
parent c9a728aaa0
commit c8ae9729ec
5 changed files with 38 additions and 6 deletions

View File

@ -2040,6 +2040,7 @@ v8_source_set("v8_base") {
"src/lookup-cache.h",
"src/lookup.cc",
"src/lookup.h",
"src/lsan.h",
"src/machine-type.cc",
"src/machine-type.h",
"src/macro-assembler-inl.h",

View File

@ -18,6 +18,7 @@
#include "src/frames.h"
#include "src/interface-descriptors.h"
#include "src/interpreter/bytecodes.h"
#include "src/lsan.h"
#include "src/machine-type.h"
#include "src/macro-assembler.h"
#include "src/objects-inl.h"
@ -500,6 +501,7 @@ void CodeAssembler::Comment(const char* format, ...) {
const int prefix_len = 2;
int length = builder.position() + 1;
char* copy = reinterpret_cast<char*>(malloc(length + prefix_len));
LSAN_IGNORE_OBJECT(copy);
MemCopy(copy + prefix_len, builder.Finalize(), length);
copy[0] = ';';
copy[1] = ' ';

View File

@ -13,6 +13,7 @@
#include "src/compiler/wasm-compiler.h"
#include "src/eh-frame.h"
#include "src/frames.h"
#include "src/lsan.h"
#include "src/macro-assembler-inl.h"
#include "src/optimized-compilation-info.h"
@ -210,9 +211,9 @@ void CodeGenerator::AssembleCode() {
current_block_ = block->rpo_number();
unwinding_info_writer_.BeginInstructionBlock(tasm()->pc_offset(), block);
if (FLAG_code_comments) {
// TODO(titzer): these code comments are a giant memory leak.
Vector<char> buffer = Vector<char>::New(200);
char* buffer_start = buffer.start();
LSAN_IGNORE_OBJECT(buffer_start);
int next = SNPrintF(
buffer, "-- B%d start%s%s%s%s", block->rpo_number().ToInt(),
@ -712,7 +713,9 @@ void CodeGenerator::AssembleSourcePosition(SourcePosition source_position) {
buffer << source_position.InliningStack(info);
}
buffer << " --";
tasm()->RecordComment(StrDup(buffer.str().c_str()));
char* str = StrDup(buffer.str().c_str());
LSAN_IGNORE_OBJECT(str);
tasm()->RecordComment(str);
}
}

30
src/lsan.h Normal file
View File

@ -0,0 +1,30 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// LeakSanitizer support.
#ifndef V8_LSAN_H_
#define V8_LSAN_H_
#include "src/base/macros.h"
#include "src/globals.h"
// There is no compile time flag for LSan, to enable this whenever ASan is
// enabled. Note that LSan can be used as part of ASan with 'detect_leaks=1'.
#ifdef V8_USE_ADDRESS_SANITIZER
#include <sanitizer/lsan_interface.h>
#define LSAN_IGNORE_OBJECT(ptr) __lsan_ignore_object(ptr)
#else // !V8_USE_ADDRESS_SANITIZER
#define LSAN_IGNORE_OBJECT(ptr) \
static_assert(std::is_pointer<decltype(ptr)>::value || \
std::is_same<v8::internal::Address, decltype(ptr)>::value, \
"static type violation")
#endif // V8_USE_ADDRESS_SANITIZER
#endif // V8_LSAN_H_

View File

@ -418,10 +418,6 @@
# https://bugs.chromium.org/p/v8/issues/detail?id=7102
# Flaky due to huge string allocation.
'regress/regress-748069': [SKIP],
# https://crbug.com/v8/7738
# Code comments currently leak memory.
'code-comments': [SKIP],
}], # 'asan == True'
##############################################################################