2016-09-15 00:04:48 +02:00
|
|
|
// Copyright 2016 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package cc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
pctx.SourcePathVariable("relocationPackerCmd", "prebuilts/misc/${config.HostPrebuiltTag}/relocation_packer/relocation_packer")
|
|
|
|
}
|
|
|
|
|
|
|
|
var relocationPackerRule = pctx.AndroidStaticRule("packRelocations",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "rm -f $out && cp $in $out && $relocationPackerCmd $out",
|
|
|
|
CommandDeps: []string{"$relocationPackerCmd"},
|
|
|
|
})
|
|
|
|
|
|
|
|
type RelocationPackerProperties struct {
|
|
|
|
Pack_relocations *bool `android:"arch_variant"`
|
|
|
|
|
|
|
|
// This will be true even if we're embedded in Make, in which case
|
|
|
|
// we'll defer to make to actually do the packing.
|
|
|
|
PackingRelocations bool `blueprint:"mutated"`
|
2018-04-03 20:33:34 +02:00
|
|
|
|
|
|
|
// Use clang lld instead of gnu ld.
|
|
|
|
Use_clang_lld *bool
|
2016-09-15 00:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type relocationPacker struct {
|
|
|
|
Properties RelocationPackerProperties
|
|
|
|
}
|
|
|
|
|
2018-04-03 20:33:34 +02:00
|
|
|
func (p *relocationPacker) useClangLld(ctx BaseModuleContext) bool {
|
|
|
|
if p.Properties.Use_clang_lld != nil {
|
|
|
|
return Bool(p.Properties.Use_clang_lld)
|
|
|
|
}
|
|
|
|
return ctx.Config().UseClangLld()
|
|
|
|
}
|
|
|
|
|
2016-09-15 00:04:48 +02:00
|
|
|
func (p *relocationPacker) packingInit(ctx BaseModuleContext) {
|
2018-03-23 20:02:56 +01:00
|
|
|
enabled := true
|
2016-09-15 00:04:48 +02:00
|
|
|
// Relocation packer isn't available on Darwin yet
|
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
enabled = false
|
|
|
|
}
|
|
|
|
if ctx.Target().Os != android.Android {
|
|
|
|
enabled = false
|
|
|
|
}
|
2017-11-29 09:27:14 +01:00
|
|
|
if ctx.Config().Getenv("DISABLE_RELOCATION_PACKER") == "true" {
|
2016-09-15 00:04:48 +02:00
|
|
|
enabled = false
|
|
|
|
}
|
2018-04-03 20:33:34 +02:00
|
|
|
// Relocation packer does not work with lld output files.
|
|
|
|
// Packed files won't load.
|
|
|
|
if p.useClangLld(ctx) {
|
|
|
|
enabled = false
|
|
|
|
}
|
2017-09-28 02:01:44 +02:00
|
|
|
if ctx.useSdk() {
|
2016-09-15 00:04:48 +02:00
|
|
|
enabled = false
|
|
|
|
}
|
|
|
|
if p.Properties.Pack_relocations != nil &&
|
|
|
|
*p.Properties.Pack_relocations == false {
|
|
|
|
enabled = false
|
|
|
|
}
|
|
|
|
|
|
|
|
p.Properties.PackingRelocations = enabled
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *relocationPacker) needsPacking(ctx ModuleContext) bool {
|
2017-11-29 09:27:14 +01:00
|
|
|
if ctx.Config().EmbeddedInMake() {
|
2016-09-15 00:04:48 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return p.Properties.PackingRelocations
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *relocationPacker) pack(ctx ModuleContext, in, out android.ModuleOutPath, flags builderFlags) {
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-09 22:45:28 +02:00
|
|
|
Rule: relocationPackerRule,
|
|
|
|
Description: "pack relocations",
|
|
|
|
Output: out,
|
|
|
|
Input: in,
|
2016-09-15 00:04:48 +02:00
|
|
|
})
|
|
|
|
}
|