Skip to content
This repository was archived by the owner on Apr 13, 2024. It is now read-only.

Commit d671e7d

Browse files
Merge pull request #141 from ClangBuiltLinux/objcopy
turn on objcopy by default for all targets
2 parents a5262ff + 4b9394a commit d671e7d

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

driver.sh

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -eu
55
setup_variables() {
66
while [[ ${#} -ge 1 ]]; do
77
case ${1} in
8-
"AR="*|"ARCH="*|"CC="*|"LD="*|"REPO="*) export "${1?}" ;;
8+
"AR="*|"ARCH="*|"CC="*|"LD="*|"OBJCOPY"=*|"REPO="*) export "${1?}" ;;
99
"-c"|"--clean") cleanup=true ;;
1010
"-j"|"--jobs") shift; jobs=$1 ;;
1111
"-j"*) jobs=${1/-j} ;;
@@ -145,7 +145,7 @@ check_dependencies() {
145145
command -v ${readelf} &>/dev/null && break
146146
done
147147

148-
# Check for LD, CC, and AR environmental variables
148+
# Check for LD, CC, OBJCOPY, and AR environmental variables
149149
# and print the version string of each. If CC and AR
150150
# don't exist, try to find them.
151151
# lld isn't ready for all architectures so it's just
@@ -183,6 +183,14 @@ check_dependencies() {
183183
fi
184184
check_ar_version
185185
${AR} --version
186+
187+
if [[ -z "${OBJCOPY:-}" ]]; then
188+
for OBJCOPY in llvm-objcopy-9 llvm-objcopy-8 llvm-objcopy-7 llvm-objcopy "${CROSS_COMPILE:-}"objcopy; do
189+
command -v ${OBJCOPY} 2>/dev/null && break
190+
done
191+
fi
192+
check_objcopy_version
193+
${OBJCOPY} --version
186194
}
187195

188196
# Optimistically check to see that the user has a llvm-ar
@@ -206,13 +214,34 @@ check_ar_version() {
206214
fi
207215
}
208216

217+
# Optimistically check to see that the user has a llvm-objcopy
218+
# with https://reviews.llvm.org/rL357017. If they don't,
219+
# fall back to GNU objcopy and let them know.
220+
check_objcopy_version() {
221+
if ${OBJCOPY} --version | grep -q "LLVM" && \
222+
[[ $(${OBJCOPY} --version | grep version | sed -e 's/.*LLVM version //g' -e 's/[[:blank:]]*$//' -e 's/\.//g' -e 's/svn//' ) -lt 900 ]]; then
223+
set +x
224+
echo
225+
echo "${OBJCOPY} found but appears to be too old to build the kernel (needs to be at least 9.0.0)."
226+
echo
227+
echo "Please either update llvm-objcopy from your distro or build it from source!"
228+
echo
229+
echo "See https://github.com/ClangBuiltLinux/linux/issues/418 for more info."
230+
echo
231+
echo "Falling back to GNU objcopy..."
232+
echo
233+
OBJCOPY=${CROSS_COMPILE:-}objcopy
234+
set -x
235+
fi
236+
}
237+
209238
mako_reactor() {
210239
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/kbuild/kbuild.txt
211240
time \
212241
KBUILD_BUILD_TIMESTAMP="Thu Jan 1 00:00:00 UTC 1970" \
213242
KBUILD_BUILD_USER=driver \
214243
KBUILD_BUILD_HOST=clangbuiltlinux \
215-
make -j"${jobs:-$(nproc)}" CC="${CC}" HOSTCC="${CC}" LD="${LD}" HOSTLD="${HOSTLD:-ld}" AR="${AR}" "${@}"
244+
make -j"${jobs:-$(nproc)}" CC="${CC}" HOSTCC="${CC}" LD="${LD}" HOSTLD="${HOSTLD:-ld}" AR="${AR}" OBJCOPY="${OBJCOPY}" "${@}"
216245
}
217246

218247
apply_patches() {

usage.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Environment variables:
2121
clang-9, clang-8, clang-7, then clang if they are found in PATH.
2222
LD:
2323
If no LD value is specified, ${CROSS_COMPILE}ld is used. arm64 only.
24+
OBJCOPY:
25+
If no OBJCOPY value is specified, the script will attempt to set OBJCOPY
26+
to llvm-objcopy-9, llvm-objcopy-8, llvm-objcopy-7, llvm-objcopy, then
27+
${CROSS_COMPILE}objcopy if they are found in PATH.
2428
REPO:
2529
Nicknames for trees:
2630
linux (default)

0 commit comments

Comments
 (0)