forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
android: Optionally madvise(MADV_RANDOM) on .text.
This CL adds: - "anchor" functions at the beginning and end of .text: these are already used in lightweight_cygprofile.cc, and require the orderfile to be properly constructed, which is the case since https://chromium-review.googlesource.com/753882. These functions are trickier for regular builds, as they use --icf=all. - madvise(MADV_RANDOM): disable kernel readahead on a given range. This makes the reporting logic for code residency clearer, as it actually shows which pages are requested. This has to be called as early as possible and from all processes, and may be enabled in all builds at a later date. This is controlled by a new command-line flag, madvise-random-executable-code. Bug: 758566 Change-Id: I8c7a5ca759b355b9e632d6ad027f8d9cd8fb84e8 Reviewed-on: https://chromium-review.googlesource.com/776895 Commit-Queue: Benoit L <[email protected]> Reviewed-by: Camille Lamy <[email protected]> Reviewed-by: Lei Zhang <[email protected]> Reviewed-by: Egor Pasko <[email protected]> Reviewed-by: agrieve <[email protected]> Reviewed-by: Matthew Cary <[email protected]> Cr-Commit-Position: refs/heads/master@{#518639}
- Loading branch information
Benoit Lize
authored and
Commit Bot
committed
Nov 22, 2017
1 parent
ff6d2f3
commit 411a34f
Showing
12 changed files
with
158 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/android/library_loader/anchor_functions.h" | ||
|
||
#include "base/logging.h" | ||
|
||
// These functions are here to, respectively: | ||
// 1. Check that functions are ordered | ||
// 2. Delimit the start of .text | ||
// 3. Delimit the end of .text | ||
// | ||
// (2) and (3) require a suitably constructed orderfile, with these | ||
// functions at the beginning and end. (1) doesn't need to be in it. | ||
// | ||
// These functions are weird: this is due to ICF (Identical Code Folding). | ||
// The linker merges functions that have the same code, which would be the case | ||
// if these functions were empty, or simple. | ||
// Gold's flag --icf=safe will *not* alias functions when their address is used | ||
// in code, but as of November 2017, we use the default setting that | ||
// deduplicates function in this case as well. | ||
// | ||
// Thus these functions are made to be unique, using inline .word in assembly. | ||
// | ||
// Note that code |CheckOrderingSanity()| below will make sure that these | ||
// functions are not aliased, in case the toolchain becomes really clever. | ||
extern "C" { | ||
|
||
void dummy_function_to_check_ordering() { | ||
asm(".word 0xe19c683d"); | ||
asm(".word 0xb3d2b56"); | ||
} | ||
|
||
void dummy_function_to_anchor_text() { | ||
asm(".word 0xe1f8940b"); | ||
asm(".word 0xd5190cda"); | ||
} | ||
|
||
void dummy_function_at_the_end_of_text() { | ||
asm(".word 0x133b9613"); | ||
asm(".word 0xdcd8c46a"); | ||
} | ||
|
||
} // extern "C" | ||
|
||
namespace base { | ||
namespace android { | ||
|
||
const size_t kStartOfText = | ||
reinterpret_cast<size_t>(dummy_function_to_anchor_text); | ||
const size_t kEndOfText = | ||
reinterpret_cast<size_t>(dummy_function_at_the_end_of_text); | ||
|
||
void CheckOrderingSanity() { | ||
// The linker usually keeps the input file ordering for symbols. | ||
// dummy_function_to_anchor_text() should then be after | ||
// dummy_function_to_check_ordering() without ordering. | ||
// This check is thus intended to catch the lack of ordering. | ||
CHECK_LT(kStartOfText, | ||
reinterpret_cast<size_t>(&dummy_function_to_check_ordering)); | ||
CHECK_LT(kStartOfText, kEndOfText); | ||
CHECK_LT(kStartOfText, | ||
reinterpret_cast<size_t>(&dummy_function_to_check_ordering)); | ||
CHECK_LT(kStartOfText, reinterpret_cast<size_t>(&CheckOrderingSanity)); | ||
CHECK_GT(kEndOfText, reinterpret_cast<size_t>(&CheckOrderingSanity)); | ||
} | ||
|
||
} // namespace android | ||
} // namespace base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef BASE_ANDROID_LIBRARY_LOADER_ANCHOR_FUNCTIONS_H_ | ||
#define BASE_ANDROID_LIBRARY_LOADER_ANCHOR_FUNCTIONS_H_ | ||
|
||
#include <cstdint> | ||
|
||
namespace base { | ||
namespace android { | ||
|
||
// Start and end of .text, respectively. | ||
extern const size_t kStartOfText; | ||
extern const size_t kEndOfText; | ||
|
||
// Basic CHECK()s ensuring that the symbols above are correctly set. | ||
void CheckOrderingSanity(); | ||
|
||
} // namespace android | ||
} // namespace base | ||
|
||
#endif // BASE_ANDROID_LIBRARY_LOADER_ANCHOR_FUNCTIONS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters