1// Copyright 2019 The Chromium OS Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5package main 6 7func processPieFlags(builder *commandBuilder) { 8 fpieMap := map[string]bool{"-D__KERNEL__": true, "-fPIC": true, "-fPIE": true, "-fno-PIC": true, "-fno-PIE": true, 9 "-fno-pic": true, "-fno-pie": true, "-fpic": true, "-fpie": true, "-nopie": true, 10 "-nostartfiles": true, "-nostdlib": true, "-pie": true, "-static": true} 11 12 pieMap := map[string]bool{"-D__KERNEL__": true, "-A": true, "-fno-PIC": true, "-fno-PIE": true, "-fno-pic": true, "-fno-pie": true, 13 "-nopie": true, "-nostartfiles": true, "-nostdlib": true, "-pie": true, "-r": true, "--shared": true, 14 "-shared": true, "-static": true} 15 16 pie := false 17 fpie := false 18 if builder.target.abi != "eabi" { 19 for _, arg := range builder.args { 20 if arg.fromUser { 21 if fpieMap[arg.value] { 22 fpie = true 23 } 24 if pieMap[arg.value] { 25 pie = true 26 } 27 } 28 } 29 } 30 builder.transformArgs(func(arg builderArg) string { 31 // Remove -nopie as it is a non-standard flag. 32 if arg.value == "-nopie" { 33 return "" 34 } 35 if fpie && !arg.fromUser && arg.value == "-fPIE" { 36 return "" 37 } 38 if pie && !arg.fromUser && arg.value == "-pie" { 39 return "" 40 } 41 return arg.value 42 }) 43} 44