Skip to content

Commit

Permalink
build_library: support multi-arch in generate_au_zip
Browse files Browse the repository at this point in the history
To be able to support arm64 native SDK without cross builds, we should
make generate_au_zip support both architectures, amd64 and arm64.
Without doing that, `build_image` fails with `ERROR : Required
WHITE_LIST items ld-linux-x86-64.so.2 not found!!!`, because the
script recognizes only amd64 libs in WHITE_LIST.

We should first determine the architecture in build_image, before
running generate_au_zip, and pass the architecture, either amd64 or
arm64. Also add allow_list and ld_linux parameters to necessary
functions.
  • Loading branch information
Dongsu Park committed Aug 13, 2021
1 parent a7f251d commit 34cb6d3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build_library/build_image_util.sh
Expand Up @@ -83,7 +83,7 @@ zip_update_tools() {
# Make sure some vars this script needs are exported
export REPO_MANIFESTS_DIR SCRIPTS_DIR
"${BUILD_LIBRARY_DIR}/generate_au_zip.py" \
--output-dir "${BUILD_DIR}" --zip-name "${update_zip}"
--arch "$(get_sdk_arch)" --output-dir "${BUILD_DIR}" --zip-name "${update_zip}"

upload_image "${BUILD_DIR}/${update_zip}"
}
Expand Down
42 changes: 30 additions & 12 deletions build_library/generate_au_zip.py
Expand Up @@ -32,6 +32,9 @@
'/usr/bin/bsdiff',
'/usr/bin/bspatch']

LD_LINUX_AMD64 = 'ld-linux-x86-64.so.2'
LD_LINUX_ARM64 = 'ld-linux-aarch64.so.1'

# These files will be ignored when present in the dependancy list.
DENY_LIST = [
# This library does not exist on disk, but is inserted into the
Expand All @@ -40,9 +43,14 @@
]

# These files MUST be present in the dependancy list.
ALLOW_LIST = [
# Update WrapExecutableFiles if this file changes names
'ld-linux-x86-64.so.2',
# Update WrapExecutableFiles if this file changes names.
# Each architecture requires different allow list libs.
ALLOW_LIST_AMD64 = [
LD_LINUX_AMD64,
]

ALLOW_LIST_ARM64 = [
LD_LINUX_ARM64,
]

LIB_DIR = 'lib.so'
Expand Down Expand Up @@ -93,7 +101,7 @@ def _SplitAndStrip(data):
return return_list


def DepsToCopy(ldd_files):
def DepsToCopy(ldd_files, allow_list):
"""Returns a list of deps for a given dynamic executables list.
Args:
ldd_files: List of dynamic files that needs to have the deps evaluated
Expand Down Expand Up @@ -130,11 +138,11 @@ def DepsToCopy(ldd_files):
sys.exit(1)

result = _ExcludeDenylist(list(libs), DENY_LIST)
_EnforceAllowList(list(libs), ALLOW_LIST)
_EnforceAllowList(list(libs), allow_list=allow_list)
return result


def CopyRequiredFiles(dest_files_root):
def CopyRequiredFiles(dest_files_root, allow_list):
"""Generates a list of files that are required for au-generator zip file
Args:
dest_files_root: location of the directory where we should copy the files
Expand All @@ -161,7 +169,7 @@ def CopyRequiredFiles(dest_files_root):
logging.exception("Copying '%s' to %s failed", file_name, dest_files_root)
sys.exit(1)

libraries = DepsToCopy(ldd_files=DYNAMIC_EXECUTABLES)
libraries = DepsToCopy(ldd_files=DYNAMIC_EXECUTABLES, allow_list=allow_list)
lib_dir = os.path.join(dest_files_root, LIB_DIR)
os.mkdir(lib_dir)
for file_name in libraries:
Expand All @@ -188,7 +196,7 @@ def CopyRequiredFiles(dest_files_root):
sys.exit(1)


def WrapExecutableFiles(dest_files_root):
def WrapExecutableFiles(dest_files_root, ld_linux):
"""Our dynamically linked executalbes have to be invoked use the library
versions they were linked with inside the chroot (from libc on), as well
as the dynamic linker they were built with inside the chroot.
Expand All @@ -209,10 +217,10 @@ def WrapExecutableFiles(dest_files_root):
script.write('# Auto-generated wrapper script\n')
script.write('thisdir="$(dirname "$0")"\n')
script.write('LD_LIBRARY_PATH=\n')
script.write('exec "$thisdir/%s/ld-linux-x86-64.so.2"'
script.write('exec "$thisdir/%s/%s"'
' --library-path "$thisdir/%s"'
' "$thisdir/%s.bin" "$@"\n' %
(LIB_DIR, LIB_DIR, base_exec))
(LIB_DIR, ld_linux, LIB_DIR, base_exec))


def CleanUp(temp_dir):
Expand Down Expand Up @@ -335,6 +343,8 @@ def main():
default='au-generator.zip', help='Name of the zip file')
parser.add_option('-k', '--keep-temp', dest='keep_temp', default=False,
action='store_true', help='Keep the temp files...',)
parser.add_option('-a', '--arch', dest='arch',
default='amd64', help='Arch amd64/arm64. Default: amd64',)

(options, args) = parser.parse_args()
if options.debug:
Expand All @@ -345,8 +355,16 @@ def main():
temp_dir = CreateTempDir()
dest_files_root = os.path.join(temp_dir, 'au-generator')
os.makedirs(dest_files_root)
CopyRequiredFiles(dest_files_root=dest_files_root)
WrapExecutableFiles(dest_files_root=dest_files_root)

if options.arch == 'arm64':
ld_linux = LD_LINUX_ARM64
allow_list = ALLOW_LIST_ARM64
else:
ld_linux = LD_LINUX_AMD64
allow_list = ALLOW_LIST_AMD64

CopyRequiredFiles(dest_files_root=dest_files_root, allow_list=allow_list)
WrapExecutableFiles(dest_files_root=dest_files_root, ld_linux=ld_linux)
zip_file_name = os.path.join(temp_dir, options.zip_name)
GenerateZipFile(zip_file_name, dest_files_root)
CopyZipToFinalDestination(options.output_dir, zip_file_name)
Expand Down

0 comments on commit 34cb6d3

Please sign in to comment.