Skip to content

Commit

Permalink
Support for loading libpeerconnection dynamically instead of statically.
Browse files Browse the repository at this point in the history
This means that instead of using shared_library as the target type for
libpeerconnection, we'll support loadable_module.  This fixes issues with
test binaries that would otherwise unnecessarily depend on libpeerconnection
in shared builds.

The renderer now loads and initializes the module just before initializing the sandbox.

I'm also enabling logging in the module since we can now do that after the process CommandLine instance has been initialized.

The output directory on linux is now always the lib/ subfolder of the build directory.  This is so that FILES.cfg and installer scripts will find it reliably.  Make builds would previuosly put it in lib.target/ whereas ninja already used lib/.  (lib/ is also the folder the installer will use)

BUG=232402,233173,235379,235380
R=jam@chromium.org, jln@chromium.org, mark@chromium.org, ronghuawu@chromium.org

Review URL: https://codereview.chromium.org/14021012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197679 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tommi@chromium.org committed May 1, 2013
1 parent 0e5a13a commit e4aa290
Show file tree
Hide file tree
Showing 14 changed files with 345 additions and 103 deletions.
4 changes: 2 additions & 2 deletions chrome/chrome_dll_bundle.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,11 @@
'<(SHARED_INTERMEDIATE_DIR)/repack/chrome_200_percent.pak',
],
}],
['enable_webrtc==1 and libpeer_target_type=="shared_library"', {
['enable_webrtc==1 and libpeer_target_type!="static_library"', {
'copies': [{
'destination': '<(PRODUCT_DIR)/$(CONTENTS_FOLDER_PATH)/Libraries',
'files': [
'<(PRODUCT_DIR)/Libraries/libpeerconnection.dylib',
'<(PRODUCT_DIR)/Libraries/libpeerconnection.so',
],
}],
}],
Expand Down
4 changes: 2 additions & 2 deletions chrome/chrome_installer.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,9 @@
'<(PRODUCT_DIR)/libpdf.so',
],
}],
['libpeer_target_type=="shared_library"', {
['libpeer_target_type!="static_library"', {
'packaging_files_binaries': [
'<(SHARED_LIB_DIR)/libpeerconnection.so',
'<(PRODUCT_DIR)/lib/libpeerconnection.so',
],
}],
],
Expand Down
1 change: 1 addition & 0 deletions content/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ include_rules = [
"+third_party/angle",
"+third_party/flac",
"+third_party/gpsd",
"+third_party/libjingle",
"+third_party/mozilla",
"+third_party/npapi/bindings",
"+third_party/skia",
Expand Down
4 changes: 2 additions & 2 deletions content/content_shell.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,11 @@
'libpeer_target_type%': 'static_library',
},
'conditions': [
['libpeer_target_type=="shared_library"', {
['libpeer_target_type!="static_library"', {
'copies': [{
'destination': '<(PRODUCT_DIR)/$(CONTENTS_FOLDER_PATH)/Libraries',
'files': [
'<(PRODUCT_DIR)/Libraries/libpeerconnection.dylib',
'<(PRODUCT_DIR)/Libraries/libpeerconnection.so',
],
}],
}],
Expand Down
8 changes: 8 additions & 0 deletions content/renderer/renderer_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "content/renderer/render_process_impl.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/renderer_main_platform_delegate.h"
#include "third_party/libjingle/overrides/init_webrtc.h"
#include "ui/base/ui_base_switches.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/plugins/ppapi/ppapi_interface_factory.h"
Expand Down Expand Up @@ -188,6 +189,13 @@ int RendererMain(const MainFunctionParams& parameters) {
// Load pepper plugins before engaging the sandbox.
PepperPluginRegistry::GetInstance();
#endif
#if defined(ENABLE_WEBRTC)
// Initialize WebRTC before engaging the sandbox.
// NOTE: On linux, this call could already have been made from
// zygote_main_linux.cc. However, calling multiple times from the same thread
// is OK.
InitializeWebRtcModule();
#endif

{
#if defined(OS_WIN) || defined(OS_MACOSX)
Expand Down
4 changes: 4 additions & 0 deletions content/zygote/zygote_main_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "sandbox/linux/services/libc_urandom_override.h"
#include "sandbox/linux/suid/client/setuid_sandbox_client.h"
#include "third_party/icu/public/i18n/unicode/timezone.h"
#include "third_party/libjingle/overrides/init_webrtc.h"
#include "third_party/skia/include/ports/SkFontConfigInterface.h"

#if defined(OS_LINUX)
Expand Down Expand Up @@ -281,6 +282,9 @@ static void PreSandboxInit() {
// Ensure access to the Pepper plugins before the sandbox is turned on.
PepperPluginRegistry::PreloadModules();
#endif
#if defined(ENABLE_WEBRTC)
InitializeWebRtcModule();
#endif
}

#if !defined(CHROMIUM_SELINUX)
Expand Down
64 changes: 38 additions & 26 deletions third_party/libjingle/libjingle.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,10 @@
],
},
'sources': [
'overrides/init_webrtc.cc',
'overrides/init_webrtc.h',
'overrides/talk/media/webrtc/webrtcexport.h',

'<(libjingle_source)/talk/app/webrtc/audiotrack.cc',
'<(libjingle_source)/talk/app/webrtc/audiotrack.h',
'<(libjingle_source)/talk/app/webrtc/datachannel.cc',
Expand All @@ -642,12 +646,12 @@
'<(libjingle_source)/talk/app/webrtc/localaudiosource.h',
'<(libjingle_source)/talk/app/webrtc/localvideosource.cc',
'<(libjingle_source)/talk/app/webrtc/localvideosource.h',
'<(libjingle_source)/talk/app/webrtc/mediaconstraintsinterface.cc',
'<(libjingle_source)/talk/app/webrtc/mediaconstraintsinterface.h',
'<(libjingle_source)/talk/app/webrtc/mediastream.cc',
'<(libjingle_source)/talk/app/webrtc/mediastream.h',
'<(libjingle_source)/talk/app/webrtc/mediastreamhandler.cc',
'<(libjingle_source)/talk/app/webrtc/mediastreamhandler.h',
'<(libjingle_source)/talk/app/webrtc/mediaconstraintsinterface.cc',
'<(libjingle_source)/talk/app/webrtc/mediaconstraintsinterface.h',
'<(libjingle_source)/talk/app/webrtc/mediastreaminterface.h',
'<(libjingle_source)/talk/app/webrtc/mediastreamprovider.h',
'<(libjingle_source)/talk/app/webrtc/mediastreamproxy.h',
Expand Down Expand Up @@ -757,18 +761,10 @@
],
'conditions': [
['libpeer_allocator_shim==1 and '
'libpeer_target_type=="shared_library" and '
'component!="shared_library"', {
'libpeer_target_type!="static_library" and OS!="mac"', {
'sources': [
'overrides/allocator_shim/allocator_stub.cc',
],
'sources/': [
# |allocator_stub.cc| will include this file directly to ensure
# that the stub code gets included with whatever depends on
# peerconnectionfactory, also includes the stub code. If we
# don't do that, the linker is free to discard the stub code
# since it by itself does not have any dependencies.
['exclude', '<(libjingle_source)/talk/app/webrtc/peerconnectionfactory.cc'],
'overrides/allocator_shim/allocator_stub.h',
],
}],
['enabled_libjingle_device_manager==1', {
Expand Down Expand Up @@ -852,7 +848,7 @@
'<(DEPTH)/third_party/webrtc/modules/modules.gyp:video_render_module',
'libjingle',
],
}, # target libpeerconnection
}, # target libjingle_webrtc
{
'target_name': 'libpeerconnection',
'type': '<(libpeer_target_type)',
Expand All @@ -869,22 +865,25 @@
'<@(libjingle_peerconnection_additional_deps)',
'libjingle_webrtc',
],
'export_dependent_settings': [
'<(DEPTH)/third_party/libjingle/libjingle.gyp:libjingle_webrtc',
],
'conditions': [
['libpeer_allocator_shim==1 and '
'libpeer_target_type=="shared_library" and '
'component!="shared_library"', {
'libpeer_target_type!="static_library"', {
'sources': [
'overrides/allocator_shim/allocator_proxy.cc',
'overrides/initialize_module.cc',
],
'conditions': [
['OS!="mac"', {
'sources': [
'overrides/allocator_shim/allocator_proxy.cc',
],
}],
],
}],
['"<(libpeer_target_type)"=="shared_library"', {
['"<(libpeer_target_type)"!="static_library"', {
# Used to control symbol export/import.
'defines': [ 'LIBPEERCONNECTION_IMPLEMENTATION=1' ],
}],
['OS=="win" and "<(libpeer_target_type)"=="shared_library"', {
['OS=="win" and "<(libpeer_target_type)"!="static_library"', {
'link_settings': {
'libraries': [
'-lsecur32.lib',
Expand All @@ -893,17 +892,30 @@
],
},
}],
['OS=="mac" and libpeer_target_type=="shared_library"', {
'xcode_settings': {
'DYLIB_INSTALL_NAME_BASE': '@loader_path/Libraries',
},
['OS!="win" and "<(libpeer_target_type)"!="static_library"', {
'cflags': [
# For compatibility with how we export symbols from this
# target on Windows. This also prevents the linker from
# picking up symbols from this target that should be linked
# in from other libjingle libs.
'-fvisibility=hidden',
],
}],
['OS=="mac" and libpeer_target_type!="static_library"', {
'product_dir': '<(PRODUCT_DIR)/Libraries',
'product_name': 'libpeerconnection',
}],
['OS=="android"', {
'standalone_static_library': 1,
}],
['OS=="linux" and libpeer_target_type!="static_library"', {
# The installer and various tools depend on finding the .so
# in this directory and not lib.target as will otherwise be
# the case with make builds.
'product_dir': '<(PRODUCT_DIR)/lib',
}],
],
}, # target peerconnection
}, # target libpeerconnection
],
}],
],
Expand Down
30 changes: 7 additions & 23 deletions third_party/libjingle/overrides/allocator_shim/allocator_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <new>
#include "allocator_shim/allocator_stub.h"

#include "talk/base/basictypes.h"

typedef void* (*AllocateFunction)(std::size_t);
typedef void (*DellocateFunction)(void*);

#ifndef LIBPEERCONNECTION_IMPLEMENTATION
#if !defined(LIBPEERCONNECTION_IMPLEMENTATION) || defined(LIBPEERCONNECTION_LIB)
#error "Only compile the allocator proxy with the shared_library implementation"
#endif

#ifdef WIN32
#define ALLOC_EXPORT __declspec(dllexport)
#else
#define ALLOC_EXPORT __attribute__((visibility("default")))
#if defined(OS_MACOSX)
#error "The allocator proxy isn't supported (or needed) on mac."
#endif

static AllocateFunction g_alloc = NULL;
static DellocateFunction g_dealloc = NULL;

// This function will be called by the client code to initialize the allocator
// routines (see allocator_stub.cc).
ALLOC_EXPORT
bool SetProxyAllocator(AllocateFunction alloc, DellocateFunction dealloc) {
g_alloc = alloc;
g_dealloc = dealloc;
return true;
}
extern AllocateFunction g_alloc;
extern DellocateFunction g_dealloc;

// Override the global new/delete routines and proxy them over to the allocator
// routines handed to us via SetProxyAllocator.
// routines handed to us via InitializeModule.

void* operator new(std::size_t n) throw() {
return g_alloc(n);
Expand Down
53 changes: 5 additions & 48 deletions third_party/libjingle/overrides/allocator_shim/allocator_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <new>
#include "allocator_shim/allocator_stub.h"

#include "talk/base/basictypes.h"


typedef void* (*AllocateFunction)(std::size_t);
typedef void (*DellocateFunction)(void*);

#ifdef LIBPEERCONNECTION_IMPLEMENTATION
#error "Only compile the allocator stub with the client implementation"
#endif

#ifdef WIN32
#define ALLOC_IMPORT __declspec(dllimport)
#else
#define ALLOC_IMPORT
#if defined(OS_MACOSX)
#error "The allocator stub isn't supported (or needed) on mac."
#endif

// The stub implementations that forward new / delete calls to the allocator
// in the current binary (usually tcmalloc).

static void* Allocate(std::size_t n) {
void* Allocate(std::size_t n) {
return operator new(n);
}

static void Dellocate(void* p) {
void Dellocate(void* p) {
return operator delete(p);
}

ALLOC_IMPORT
bool SetProxyAllocator(AllocateFunction a, DellocateFunction d);

// Initialize the proxy by supplying it with a pointer to our
// allocator/deallocator routines.
// This unfortunately costs a single static initializer. The alternatives
// are:
// * A circular reference from libjingle back to chrome (or any other binary)
// * Reworking libjingle interfaces to not use stl types in classinterfaces.
// This is currently not feasible.
// * Hack internal peerconnectionfactory implementation details such as
// PeerConnectionFactory::Initialize to initialize the proxy. While possible,
// this would be very prone to regressions due to any changes in the libjingle
// library.
// * Make modifications to libjingle to support initializing the proxy when
// needed. I'm (tommi) currently working on this.
static const bool proxy_allocator_initialized =
SetProxyAllocator(&Allocate, &Dellocate);

// Include the implementation of peerconnectionfactory.cc here.
// This is done to ensure that the stub initialization code and
// peerconnectionfactory belong to the same object file. That way the
// linker cannot discard the necessary stub initialization code that goes with
// the factory, even though there aren't any explicit dependencies.
// See libjingle.gyp for how we exclude peerconnectionfactory.cc from the
// target in this case.
#include "talk/app/webrtc/peerconnectionfactory.cc"
24 changes: 24 additions & 0 deletions third_party/libjingle/overrides/allocator_shim/allocator_stub.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2013 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 THIRD_PARTY_LIBJINGLE_OVERRIDES_ALLOCATOR_SHIM_ALLOCATOR_STUB_H_
#define THIRD_PARTY_LIBJINGLE_OVERRIDES_ALLOCATOR_SHIM_ALLOCATOR_STUB_H_

#include <new>

#include "base/basictypes.h"

#if !defined(OS_MACOSX)

typedef void* (*AllocateFunction)(std::size_t);
typedef void (*DellocateFunction)(void*);

// The stub implementations that forward new / delete calls to the allocator
// in the current binary (i.e. tcmalloc).
void* Allocate(std::size_t n);
void Dellocate(void* p);

#endif // OS_MACOSX

#endif // THIRD_PARTY_LIBJINGLE_OVERRIDES_ALLOCATOR_SHIM_ALLOCATOR_STUB_H_
Loading

0 comments on commit e4aa290

Please sign in to comment.