1// Copyright 2018 Google Inc. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package cc 16 17import ( 18 "android/soong/android" 19) 20 21type XomProperties struct { 22 Xom *bool 23} 24 25type xom struct { 26 Properties XomProperties 27} 28 29func (xom *xom) props() []interface{} { 30 return []interface{}{&xom.Properties} 31} 32 33func (xom *xom) begin(ctx BaseModuleContext) {} 34 35func (xom *xom) deps(ctx BaseModuleContext, deps Deps) Deps { 36 return deps 37} 38 39func (xom *xom) flags(ctx ModuleContext, flags Flags) Flags { 40 disableXom := false 41 42 if !ctx.Config().EnableXOM() || ctx.Config().XOMDisabledForPath(ctx.ModuleDir()) { 43 disableXom = true 44 } 45 46 if xom.Properties.Xom != nil && !*xom.Properties.Xom { 47 return flags 48 } 49 50 // If any static dependencies have XOM disabled, we should disable XOM in this module, 51 // the assumption being if it's been explicitly disabled then there's probably incompatible 52 // code in the library which may get pulled in. 53 if !disableXom { 54 ctx.VisitDirectDeps(func(m android.Module) { 55 cc, ok := m.(*Module) 56 if !ok || cc.xom == nil || !cc.static() { 57 return 58 } 59 if cc.xom.Properties.Xom != nil && !*cc.xom.Properties.Xom { 60 disableXom = true 61 return 62 } 63 }) 64 } 65 66 // Enable execute-only if none of the dependencies disable it, 67 // also if it's explicitly set true (allows overriding dependencies disabling it). 68 if !disableXom || (xom.Properties.Xom != nil && *xom.Properties.Xom) { 69 // XOM is only supported on AArch64 when using lld. 70 if ctx.Arch().ArchType == android.Arm64 && ctx.useClangLld(ctx) { 71 flags.LdFlags = append(flags.LdFlags, "-Wl,-execute-only") 72 } 73 } 74 75 return flags 76} 77