Commit 79fc11a5 authored by Yun Liu's avatar Yun Liu Committed by Commit Bot

Implement __cxa_pure_virtual to avoid undefined symbol error

"undefined symbol: __cxa_pure_virtual" will happen when building
//base/android/linker:chromium_android_linker with
use_clang_coverage = true

It seems we can use infinite loop to avoid this error:
https://stackoverflow.com/questions/920500/what-is-the-purpose-of-cxa-pure-virtual


Bug: 1018780
Change-Id: I97cc0a495320c4ede1ecd43cf1b7816b58646960
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1968050
Commit-Queue: Yun Liu <yliuyliu@google.com>
Reviewed-by: default avatarRoss McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726178}
parent 2ff1dae2
......@@ -105,3 +105,5 @@ Local Modifications:
- Add a document about testing the crazy linker in a Chromium checkout
- Remove unnecessary alignment check for size of area that is about to mmap(2).
- Implement __cxa_pure_virtual to avoid undefined symbol error.
......@@ -6,6 +6,7 @@
#include <errno.h>
#include <string.h>
#include <unistd.h>
#ifdef __ANDROID__
#include <android/log.h>
......@@ -17,6 +18,16 @@
namespace crazy {
// Log fatal error and exit.
void LogFatalAndExit(const char* message) {
#ifdef __ANDROID__
__android_log_write(ANDROID_LOG_FATAL, "crazy_linker", message);
#else
::write(STDERR_FILENO, message, sizeof(message) - 1);
#endif
_exit(1);
}
#if CRAZY_DEBUG
namespace {
......
......@@ -29,6 +29,9 @@ template <bool> struct CompileAssert { };
namespace crazy {
// Log fatal error and exit.
void LogFatalAndExit(const char* message);
#if CRAZY_DEBUG
void Log(const char* location, const char* fmt, ...);
......
......@@ -59,6 +59,12 @@
#define DT_PREINIT_ARRAYSZ 33
#endif
// Avoid undefined symbol:__cxa_pure_virtual error.
extern "C" void __cxa_pure_virtual() {
static const char kFatalMessage[] = "Pure virtual function was called!";
crazy::LogFatalAndExit(kFatalMessage);
}
namespace crazy {
namespace {
......
......@@ -14,6 +14,7 @@
#include <android/log.h>
#endif
#include "crazy_linker_debug.h"
#include "crazy_linker_util.h"
// Note: unit-testing support files are in crazy_linker_files_mock.cpp
......@@ -199,12 +200,7 @@ void* operator new(size_t size) {
// runtime. Hence our fatal message does not contain the number of
// bytes requested by the allocation.
static const char kFatalMessage[] = "Out of memory!";
#ifdef __ANDROID__
__android_log_write(ANDROID_LOG_FATAL, "crazy_linker", kFatalMessage);
#else
::write(STDERR_FILENO, kFatalMessage, sizeof(kFatalMessage) - 1);
#endif
_exit(1);
crazy::LogFatalAndExit(kFatalMessage);
#if defined(__GNUC__)
__builtin_unreachable();
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment