aboutsummaryrefslogtreecommitdiffstats
path: root/cc/linker.go
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2017-08-18 16:52:25 -0700
committerJustin Yun <justinyun@google.com>2017-08-23 12:54:54 +0900
commitef88ae2369aa9a097941bf1bff7823589ffc819f (patch)
treea5e0530520764a2b2e8525a15aaa8c7864eb0f1b /cc/linker.go
parent0b062130dcbaa40498e133f8d44de4148d6a8427 (diff)
downloadbuild_soong-ef88ae2369aa9a097941bf1bff7823589ffc819f.tar.gz
build_soong-ef88ae2369aa9a097941bf1bff7823589ffc819f.tar.bz2
build_soong-ef88ae2369aa9a097941bf1bff7823589ffc819f.zip
Make libdl.so be loaded after libc.so
Make sure that libdl is always after libc on the command line. Simplifies the logic to always support system_shared_libs for sdk and vndk builds. For backwards compatibility without updating lots of Android.bp files, allow libdl to be listed in shared_libs as long as it is also in system_shared_libs or libc is not in system_shared_libs. Remove all the places that libdl is added as a dependency, since it will always be present unless explicitly removed now. Bug: 62815515 Test: m -j checkbuild Change-Id: I0233178ffea87a2f0b82190746022476304a68e2
Diffstat (limited to 'cc/linker.go')
-rw-r--r--cc/linker.go48
1 files changed, 23 insertions, 25 deletions
diff --git a/cc/linker.go b/cc/linker.go
index a0f3bc28..678b992d 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -48,8 +48,8 @@ type BaseLinkerProperties struct {
No_default_compiler_flags *bool
// list of system libraries that will be dynamically linked to
- // shared library and executable modules. If unset, generally defaults to libc
- // and libm. Set to [] to prevent linking against libc and libm.
+ // shared library and executable modules. If unset, generally defaults to libc,
+ // libm, and libdl. Set to [] to prevent linking against the defaults.
System_shared_libs []string
// allow the module to contain undefined symbols. By default,
@@ -153,34 +153,32 @@ func (linker *baseLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
}
if !ctx.static() {
- // libdl should always appear after libc in dt_needed list - see below
- // the only exception is when libc is not in linker.Properties.System_shared_libs
- // such as for libc module itself
- if inList("libc", linker.Properties.System_shared_libs) {
- _, deps.SharedLibs = removeFromList("libdl", deps.SharedLibs)
+ systemSharedLibs := linker.Properties.System_shared_libs
+ if systemSharedLibs == nil {
+ systemSharedLibs = []string{"libc", "libm", "libdl"}
}
- if linker.Properties.System_shared_libs != nil {
- if !inList("libdl", linker.Properties.System_shared_libs) &&
- inList("libc", linker.Properties.System_shared_libs) {
- linker.Properties.System_shared_libs = append(linker.Properties.System_shared_libs,
- "libdl")
+ if inList("libdl", deps.SharedLibs) {
+ // If system_shared_libs has libc but not libdl, make sure shared_libs does not
+ // have libdl to avoid loading libdl before libc.
+ if inList("libc", systemSharedLibs) {
+ if !inList("libdl", systemSharedLibs) {
+ ctx.PropertyErrorf("shared_libs",
+ "libdl must be in system_shared_libs, not shared_libs")
+ }
+ _, deps.SharedLibs = removeFromList("libdl", deps.SharedLibs)
}
- deps.LateSharedLibs = append(deps.LateSharedLibs,
- linker.Properties.System_shared_libs...)
- } else if !ctx.sdk() && !ctx.vndk() {
- deps.LateSharedLibs = append(deps.LateSharedLibs, "libc", "libm", "libdl")
}
- }
- if ctx.sdk() {
- deps.SharedLibs = append(deps.SharedLibs,
- "libc",
- "libm",
- "libdl",
- )
- }
- if ctx.vndk() {
+ // If libc and libdl are both in system_shared_libs make sure libd comes after libc
+ // to avoid loading libdl before libc.
+ if inList("libdl", systemSharedLibs) && inList("libc", systemSharedLibs) &&
+ indexList("libdl", systemSharedLibs) < indexList("libc", systemSharedLibs) {
+ ctx.PropertyErrorf("system_shared_libs", "libdl must be after libc")
+ }
+
+ deps.LateSharedLibs = append(deps.LateSharedLibs, systemSharedLibs...)
+ } else if ctx.sdk() || ctx.vndk() {
deps.LateSharedLibs = append(deps.LateSharedLibs, "libc", "libm", "libdl")
}
}