1package sanitizer_status
2
3import (
4	"android/soong/android"
5	"android/soong/cc"
6)
7
8func init() {
9	android.RegisterModuleType("sanitizer_status_library_shared",
10		libraryFactory)
11}
12
13func libraryFactory() android.Module {
14	module := cc.LibrarySharedFactory()
15	android.AddLoadHook(module, loadHook)
16	return module
17}
18
19func loadHook(ctx android.LoadHookContext) {
20	type props struct {
21		Cflags []string
22	}
23
24	p := &props{}
25
26	sanitizers := ctx.Config().SanitizeDevice()
27
28	if android.InList("address", sanitizers) {
29		p.Cflags = append(p.Cflags, "-DANDROID_SANITIZE_ADDRESS=1")
30	}
31	if android.InList("hwaddress", sanitizers) {
32		p.Cflags = append(p.Cflags, "-DANDROID_SANITIZE_HWADDRESS=1")
33	}
34	if android.InList("coverage", sanitizers) {
35		p.Cflags = append(p.Cflags, "-DANDROID_SANITIZE_COVERAGE=1")
36	}
37
38	ctx.AppendProperties(p)
39}
40