Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hwasan toolchain #677

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions core/androidbp_cclibs.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,9 @@ func addMTEProps(m bpwriter.Module, props AndroidMTEProps) {
}
}

func addHWASANProps(m bpwriter.Module, props Build) {
memtagHeap := proptools.Bool(props.AndroidMTEProps.Mte.Memtag_heap)
if memtagHeap {
return
}
if proptools.Bool(props.Hwasan_enabled) {
g := m.NewGroup("sanitize")
g.AddBool("hwaddress", true)
}
func addHWASANProps(m bpwriter.Module) {
g := m.NewGroup("sanitize")
g.AddBool("hwaddress", true)
}

func addRequiredModules(mod bpwriter.Module, m ModuleLibrary, ctx blueprint.ModuleContext) {
Expand Down Expand Up @@ -330,7 +324,7 @@ func addCcLibraryProps(mod bpwriter.Module, m ModuleLibrary, ctx blueprint.Modul
}
}

func addBinaryProps(mod bpwriter.Module, m ModuleBinary, ctx blueprint.ModuleContext, g *androidBpGenerator) {
func addBinaryProps(mod bpwriter.Module, m *ModuleBinary, ctx blueprint.ModuleContext, g *androidBpGenerator) {
// Handle installation
if _, installRel, ok := getSoongInstallPath(m.getInstallableProps()); ok {
// Only setup multilib for target modules.
Expand All @@ -356,8 +350,11 @@ func addBinaryProps(mod bpwriter.Module, m ModuleBinary, ctx blueprint.ModuleCon
bc := GetModuleBackendConfiguration(ctx, m)
if bc != nil {
addMTEProps(mod, bc.GetMteProps(ctx))
if !proptools.Bool(bc.GetMteProps(ctx).Mte.Diag_memtag_heap) && bc.IsHwAsanEnabled() {
addHWASANProps(mod)
}
}
addHWASANProps(mod, m.Properties.Build)

}

func addStaticOrSharedLibraryProps(mod bpwriter.Module, m ModuleLibrary, ctx blueprint.ModuleContext) {
Expand All @@ -375,7 +372,6 @@ func addStaticOrSharedLibraryProps(mod bpwriter.Module, m ModuleLibrary, ctx blu
if m.Properties.TargetType == toolchain.TgtTypeTarget && !linksToGeneratedLibrary(ctx) {
mod.AddString("compile_multilib", "both")
}
addHWASANProps(mod, m.Properties.Build)
}

func addStripProp(m bpwriter.Module) {
Expand Down Expand Up @@ -574,7 +570,7 @@ func (g *androidBpGenerator) binaryActions(m *ModuleBinary, ctx blueprint.Module
}

addCcLibraryProps(mod, m.ModuleLibrary, ctx)
addBinaryProps(mod, *m, ctx, g)
addBinaryProps(mod, m, ctx, g)
bc := GetModuleBackendConfiguration(ctx, m)
if bc.strip() {
addStripProp(mod)
Expand Down Expand Up @@ -626,6 +622,10 @@ func (g *androidBpGenerator) sharedActions(m *ModuleSharedLibrary, ctx blueprint
addStripProp(mod)
}

if !proptools.Bool(bc.GetMteProps(ctx).Mte.Diag_memtag_heap) && bc.IsHwAsanEnabled() {
addHWASANProps(mod)
}

versionScript := g.getVersionScript(&m.ModuleLibrary, ctx)
if versionScript != nil {
mod.AddString("version_script", *versionScript)
Expand All @@ -652,6 +652,13 @@ func (g *androidBpGenerator) staticActions(m *ModuleStaticLibrary, ctx blueprint

addCcLibraryProps(mod, m.ModuleLibrary, ctx)
addStaticOrSharedLibraryProps(mod, m.ModuleLibrary, ctx)

bc := GetModuleBackendConfiguration(ctx, m)
if bc != nil {
if !proptools.Bool(bc.GetMteProps(ctx).Mte.Diag_memtag_heap) && bc.IsHwAsanEnabled() {
addHWASANProps(mod)
}
}
}

func proxyCflags(m *ModuleStrictLibrary) []string {
Expand Down Expand Up @@ -701,6 +708,10 @@ func (g *androidBpGenerator) strictLibraryActions(m *ModuleStrictLibrary, ctx bl

addProvenanceProps(ctx, mod, m)

if bc != nil && !proptools.Bool(bc.GetMteProps(ctx).Mte.Diag_memtag_heap) && bc.IsHwAsanEnabled() {
addHWASANProps(mod)
}

// TODO: Make addPGOProps generic and enable it if needed
// addPGOProps(mod, m.Properties.Build.AndroidPGOProps)

Expand Down Expand Up @@ -748,6 +759,10 @@ func (g *androidBpGenerator) executableTestActions(m *ModuleTest, ctx blueprint.

addProvenanceProps(ctx, mod, m)

if bc != nil && !proptools.Bool(bc.GetMteProps(ctx).Mte.Diag_memtag_heap) && bc.IsHwAsanEnabled() {
addHWASANProps(mod)
}

// Avoid using cc_test default setup
// TODO: `relative_install_path` needed - Module install directory may only be disabled if relative_install_path is set
// mod.AddBool("no_named_install_directory", true)
Expand Down Expand Up @@ -781,6 +796,10 @@ func (g *androidBpGenerator) strictBinaryActions(m *ModuleStrictBinary, ctx blue
addStripProp(mod)
}

if bc != nil && !proptools.Bool(bc.GetMteProps(ctx).Mte.Diag_memtag_heap) && bc.IsHwAsanEnabled() {
addHWASANProps(mod)
}

if m.Properties.TargetType == toolchain.TgtTypeTarget && !linksToGeneratedLibrary(ctx) {
mod.AddString("compile_multilib", "both")
}
Expand Down
7 changes: 4 additions & 3 deletions core/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ type binaryInterface interface {
file.Provider // A binary can provide itself as a source
}

var _ binaryInterface = (*ModuleBinary)(nil) // impl check
var _ libraryInterface = (*ModuleBinary)(nil) // impl check
var _ BackendConfiguration = (*ModuleBinary)(nil) // impl check
var _ binaryInterface = (*ModuleBinary)(nil) // impl check
var _ libraryInterface = (*ModuleBinary)(nil) // impl check
var _ BackendConfiguration = (*ModuleBinary)(nil) // impl check
var _ BackendConfigurationProvider = (*ModuleBinary)(nil) // impl check

func (m *ModuleBinary) OutFiles() (srcs file.Paths) {
return file.Paths{file.NewPath(m.outputName(), string(m.getTarget()), file.TypeBinary|file.TypeExecutable|file.TypeInstallable)}
Expand Down
5 changes: 5 additions & 0 deletions core/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ARM-software/bob-build/internal/utils"

"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)

var depOutputsVarRegexp = regexp.MustCompile(`^\$\{(.+)_out\}$`)
Expand Down Expand Up @@ -461,6 +462,10 @@ func (m *ModuleLibrary) GetMteProps(blueprint.ModuleContext) AndroidMTEProps {
return m.Properties.AndroidMTEProps
}

func (m *ModuleLibrary) IsHwAsanEnabled() bool {
return proptools.Bool(m.Properties.Build.Hwasan_enabled)
}

func (m *ModuleLibrary) IsForwardingSharedLibrary() bool {
return m.Properties.isForwardingSharedLibrary()
}
Expand Down
4 changes: 3 additions & 1 deletion core/library_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const (
var _ linkableModule = (*ModuleSharedLibrary)(nil)
var _ sharedLibProducer = (*ModuleSharedLibrary)(nil)
var _ stripable = (*ModuleSharedLibrary)(nil)
var _ libraryInterface = (*ModuleSharedLibrary)(nil) // impl check
var _ libraryInterface = (*ModuleSharedLibrary)(nil) // impl check
var _ BackendConfiguration = (*ModuleSharedLibrary)(nil) // impl check
var _ BackendConfigurationProvider = (*ModuleSharedLibrary)(nil) // impl check

func (m *ModuleSharedLibrary) OutFiles() (files file.Paths) {

Expand Down
4 changes: 3 additions & 1 deletion core/library_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ type ModuleStaticLibrary struct {
ModuleLibrary
}

var _ libraryInterface = (*ModuleStaticLibrary)(nil) // impl check
var _ libraryInterface = (*ModuleStaticLibrary)(nil) // impl check
var _ BackendConfiguration = (*ModuleStaticLibrary)(nil) // impl check
var _ BackendConfigurationProvider = (*ModuleStaticLibrary)(nil) // impl check

func (m *ModuleStaticLibrary) GenerateBuildActions(ctx blueprint.ModuleContext) {
if isEnabled(m) {
Expand Down
16 changes: 11 additions & 5 deletions core/module_toolchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/ARM-software/bob-build/core/toolchain"
"github.com/ARM-software/bob-build/core/toolchain/mapper"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)

type ModuleToolchainProps struct {
Expand All @@ -31,6 +32,8 @@ type ModuleToolchainProps struct {
Build_wrapper *string

AndroidMTEProps

Hwasan_enabled *bool
}

type ToolchainFlagsProps struct {
Expand Down Expand Up @@ -64,18 +67,17 @@ type BackendConfiguration interface {
stripable
GetBuildWrapperAndDeps(blueprint.ModuleContext) (string, []string)
GetMteProps(blueprint.ModuleContext) AndroidMTEProps
IsHwAsanEnabled() bool
}

// This interface provides configuration features
type BackendConfigurationProvider interface {
GetBackendConfiguration(blueprint.ModuleContext) BackendConfiguration
}

func GetModuleBackendConfiguration(ctx blueprint.ModuleContext, m interface{}) BackendConfiguration {
if capable, ok := m.(BackendConfigurationProvider); ok {
if bc := capable.GetBackendConfiguration(ctx); bc != nil {
return bc
}
func GetModuleBackendConfiguration(ctx blueprint.ModuleContext, m BackendConfigurationProvider) BackendConfiguration {
if bc := m.GetBackendConfiguration(ctx); bc != nil {
return bc
}
return nil
}
Expand Down Expand Up @@ -169,6 +171,10 @@ func (m *ModuleToolchain) GetBuildWrapperAndDeps(ctx blueprint.ModuleContext) (s
return "", []string{}
}

func (m *ModuleToolchain) IsHwAsanEnabled() bool {
return proptools.Bool(m.Properties.Hwasan_enabled)
}

func (m *ModuleToolchain) FlagsOut() flag.Flags {
lut := flag.FlagParserTable{
{
Expand Down
Empty file.
1 change: 1 addition & 0 deletions gendiffer/tests/shared_library/hwasan/app/bplist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build.bp
14 changes: 14 additions & 0 deletions gendiffer/tests/shared_library/hwasan/app/build.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


bob_shared_library {
name: "libshared",
srcs: ["src.cpp"],
hwasan_enabled: true,
}

bob_binary {
hwasan_enabled: true,
name: "bob_binary",
srcs: ["src.cpp"],
shared_libs: ["libshared"],
}
Empty file.
27 changes: 27 additions & 0 deletions gendiffer/tests/shared_library/hwasan/out/android/Android.bp.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

genrule {
name: "_check_buildbp_updates_redacted",
srcs: ["build.bp"],
out: ["androidbp_up_to_date"],
tool_files: ["scripts/verify_hash.py"],
cmd: "python $(location scripts/verify_hash.py) --hash redacted --out $(out) -- $(in)",
}

cc_binary {
name: "bob_binary",
srcs: ["src.cpp"],
shared_libs: ["libshared"],
sanitize: {
hwaddress: true,
},
}

cc_library_shared {
name: "libshared",
srcs: ["src.cpp"],
compile_multilib: "both",
sanitize: {
hwaddress: true,
},
}

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Empty file.
Empty file.
Loading