gn2bp: Add linker script to modules
Test: m
Change-Id: I549d78baf94b1abec07782df006269ba00e2776c
diff --git a/tools/gn2bp/Android.bp.swp b/tools/gn2bp/Android.bp.swp
index 88fe070..d7e751d 100644
--- a/tools/gn2bp/Android.bp.swp
+++ b/tools/gn2bp/Android.bp.swp
@@ -1036,6 +1036,7 @@
"-Wl,--as-needed",
"-Wl,--gc-sections",
"-Wl,--icf=all",
+ "-Wl,--script,external/cronet/base/android/library_loader/anchor_functions.lds",
"-Wl,-wrap,asprintf",
"-Wl,-wrap,calloc",
"-Wl,-wrap,free",
@@ -4197,6 +4198,7 @@
"-Wl,--as-needed",
"-Wl,--gc-sections",
"-Wl,--icf=all",
+ "-Wl,--script,external/cronet/base/android/library_loader/anchor_functions.lds",
"-Wl,-wrap,asprintf",
"-Wl,-wrap,calloc",
"-Wl,-wrap,free",
@@ -4352,6 +4354,7 @@
"-Wl,--as-needed",
"-Wl,--gc-sections",
"-Wl,--icf=all",
+ "-Wl,--script,external/cronet/base/android/library_loader/anchor_functions.lds",
"-Wl,-wrap,asprintf",
"-Wl,-wrap,calloc",
"-Wl,-wrap,free",
@@ -6001,6 +6004,7 @@
"-Wl,--as-needed",
"-Wl,--gc-sections",
"-Wl,--icf=all",
+ "-Wl,--script,external/cronet/base/android/library_loader/anchor_functions.lds",
"-Wl,-wrap,asprintf",
"-Wl,-wrap,calloc",
"-Wl,-wrap,free",
@@ -6486,6 +6490,7 @@
"-Wl,--as-needed",
"-Wl,--gc-sections",
"-Wl,--icf=all",
+ "-Wl,--script,external/cronet/base/android/library_loader/anchor_functions.lds",
"-Wl,-wrap,asprintf",
"-Wl,-wrap,calloc",
"-Wl,-wrap,free",
@@ -7032,6 +7037,7 @@
"-Wl,--as-needed",
"-Wl,--gc-sections",
"-Wl,--icf=all",
+ "-Wl,--script,external/cronet/base/android/library_loader/anchor_functions.lds",
"-Wl,-wrap,asprintf",
"-Wl,-wrap,calloc",
"-Wl,-wrap,free",
@@ -7230,6 +7236,7 @@
"-Wl,--as-needed",
"-Wl,--gc-sections",
"-Wl,--icf=all",
+ "-Wl,--script,external/cronet/base/android/library_loader/anchor_functions.lds",
"-Wl,-wrap,asprintf",
"-Wl,-wrap,calloc",
"-Wl,-wrap,free",
@@ -12828,6 +12835,7 @@
"-Wl,--as-needed",
"-Wl,--gc-sections",
"-Wl,--icf=all",
+ "-Wl,--script,external/cronet/base/android/library_loader/anchor_functions.lds",
"-Wl,-wrap,asprintf",
"-Wl,-wrap,calloc",
"-Wl,-wrap,free",
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index c8d945d..8e3888c 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -157,14 +157,6 @@
# Additional arguments to apply to Android.bp rules.
additional_args = {
- # TODO: remove if not needed.
- 'cronet_aml_components_cronet_android_cronet': [
- # linker_scripts property is not available in tm-mainline-prod.
- # So use ldflags to specify linker script.
- ('ldflags',{
- get_linker_script_ldflag('base/android/library_loader/anchor_functions.lds'),
- }),
- ],
'cronet_aml_net_net': [
('export_static_lib_headers', {
'cronet_aml_net_third_party_quiche_quiche',
@@ -1303,11 +1295,17 @@
cflags |= set("-D%s" % define.replace("\"", "\\\"") for define in defines)
return cflags
-def set_module_flags(module, module_type, cflags, defines, ldflags):
+def _set_linker_script(module, libs):
+ for lib in libs:
+ if lib.endswith(".lds"):
+ module.ldflags.add(get_linker_script_ldflag(gn_utils.label_to_path(lib)))
+
+def set_module_flags(module, module_type, cflags, defines, ldflags, libs):
module.cflags.update(_get_cflags(cflags, defines))
if module_type != 'cc_object':
module.ldflags.update({flag for flag in ldflags
if flag in ldflag_allowlist or flag.startswith("-Wl,-wrap,")})
+ _set_linker_script(module, libs)
# TODO: implement proper cflag parsing.
for flag in cflags:
if '-std=' in flag:
@@ -1399,12 +1397,13 @@
module.rtti = target.rtti
if target.type in gn_utils.LINKER_UNIT_TYPES:
- set_module_flags(module, module.type, target.cflags, target.defines, target.ldflags)
+ set_module_flags(module, module.type, target.cflags, target.defines, target.ldflags, target.libs)
set_module_include_dirs(module, target.cflags, target.include_dirs)
# TODO: set_module_xxx is confusing, apply similar function to module and target in better way.
for arch_name, arch in target.arch.items():
+ # TODO(aymanm): Make libs arch-specific.
set_module_flags(module.target[arch_name], module.type,
- arch.cflags, arch.defines, arch.ldflags)
+ arch.cflags, arch.defines, arch.ldflags, [])
# -Xclang -target-feature -Xclang +mte are used to enable MTE (Memory Tagging Extensions).
# Flags which does not start with '-' could not be in the cflags so enabling MTE by
# -march and -mcpu Feature Modifiers. MTE is only available on arm64. This is needed for