forked from opendcdiag/opendcdiag
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Meson/Linux: parse the malloc.cpp source instead of malloc.cpp.o
I want to avoid having to build the .o file before extracting malloc.o from libc.a. To parse the source file, we need a clear marker, which I also used to avoid having to have duplicate declarations. Because of Meson is incapable of using backslashes in custom_target() commands (see [1]), I had to write a shell script to execute sed, so I decided to move the ar x command there too. [1] mesonbuild/meson#1564 Signed-off-by: Thiago Macieira <[email protected]>
- Loading branch information
1 parent
3796a6f
commit 9b955fb
Showing
3 changed files
with
70 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash -e | ||
# Copyright 2023 Intel Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
while [[ "$1" = *=* ]]; do | ||
# Evaluate variable assignments, like AR= and OBJCOPY= | ||
eval "$1" | ||
shift | ||
done | ||
if [[ "$1" = "--" ]]; then | ||
shift | ||
fi | ||
|
||
if [[ $# -lt 3 ]]; then | ||
cat <<EOF | ||
Extracts malloc.o from static libc and localizes symbols defined in malloc.cpp. | ||
Syntax: | ||
$0 [variable-assignments] /path/to/libc.a /path/to/malloc.cpp /path/to/output/malloc.o | ||
Variable assignments can be: | ||
AR=/path/to/ar | ||
EOF | ||
exit 0 | ||
fi | ||
|
||
# Positional arguments | ||
libc_a=$1 | ||
malloc_cpp=$2 | ||
output=$3 | ||
output_dirname=${output%/*} | ||
output_basename=${output##*/} | ||
|
||
# Define $AR and $OBJCOPY if they aren't defined. | ||
: ${AR:=ar} | ||
: ${OBJCOPY:=objcopy} | ||
|
||
# Generate the -L arguments based on DECLARE_OVERRIDE inside malloc.cpp | ||
objcopy_args=(`sed -En "/^DECLARE_OVERRIDE\((\w+)\).*/s//-L\1/p" "$malloc_cpp"`) | ||
|
||
# Extract malloc.o from libc.a | ||
"$AR" x --output "$output_dirname" "$libc_a" malloc.o | ||
|
||
# Rename if necessary | ||
[[ "$output_basename" = malloc.o ]] || mv -- "$output_dirname/malloc.o" "$output" | ||
|
||
# Transform it | ||
"$OBJCOPY" "${objcopy_args[@]}" "$output" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters