Skip to content

Instantly share code, notes, and snippets.

@ashgti
Created October 3, 2024 16:06
Show Gist options
  • Save ashgti/89909f8b384afdde8d519370a3e26b88 to your computer and use it in GitHub Desktop.
Save ashgti/89909f8b384afdde8d519370a3e26b88 to your computer and use it in GitHub Desktop.
oso_prefix bug with ld in Xcode 15.3, 15.4, 16.0
#!/usr/bin/env zsh
: "${DEVLEOPER_DIR:="$(xcode-select -p)"}"
: "${ROOT:="${TMPDIR}linker_path_bug"}"
mkdir -p $ROOT/{srcs,build_outputs,build_artifacts}
WORKING_DIR=`mktemp -d -t working_dir`
mkdir -p $WORKING_DIR
cat <<HERE > $ROOT/srcs/main.c
#include <stdio.h>
int main() {
printf("Hello world!\n");
return 0;
}
HERE
echo DEVELOPER_DIR: $DEVLEOPER_DIR
cd $ROOT
echo "\n\nCompiling...\n\n"
clang -v -g -c ./srcs/main.c -o ./build_outputs/main.o
echo "\n\nLinking...\n\n"
clang -v -o ./build_artifacts/exe1 ./build_outputs/main.o -Wl,-oso_prefix,.
clang -v -o ./build_artifacts/exe2 ./build_outputs/main.o -Wl,-oso_prefix,. -Wl,-ld_classic
echo "\n\nFrom Working directory $WORKING_DIR\n\n"
ln -s $ROOT/build_outputs $WORKING_DIR/build_outputs
ln -s $ROOT/build_artifacts $WORKING_DIR/build_artifacts
ln -s $ROOT/srcs $WORKING_DIR/srcs
cd $WORKING_DIR
clang -v -o ./build_artifacts/exe3 ./build_outputs/main.o -Wl,-oso_prefix,.
clang -v -o ./build_artifacts/exe4 ./build_outputs/main.o -Wl,-oso_prefix,. -Wl,-ld_classic
echo "\n\nChecking embedded paths\n\n"
echo "\noso_prefix (no symlinks) ld:\n"
nm -pma $ROOT/build_artifacts/exe1
echo "\noso_prefix (no symlinks) ld_classic:\n"
nm -pma $ROOT/build_artifacts/exe1
echo "\noso_prefix (.o file symlinks) ld:\n"
nm -pma $ROOT/build_artifacts/exe3
echo "\noso_prefix (.o file symlinks) ld_classic:\n"
nm -pma $ROOT/build_artifacts/exe4
oso_prefix (no symlinks) ld:
0000000000000000 (?) non-external
0000000000000000 (?) non-external /var/folders/_0/_vrx1th904x4bsf1c0_w4bhw00g80m/T/linker_path_bug/srcs/
0000000000000000 (?) non-external main.c
0000000066e86ece (?) non-external build_outputs/main.o
0000000100003f58 (__TEXT,__text) non-external
0000000100003f58 (?) non-external _main
0000000000000034 (?) non-external
0000000100003f58 (__TEXT,__text) non-external
0000000000000000 (?) non-external
0000000100000000 (__TEXT,__text) [referenced dynamically] external __mh_execute_header
0000000100003f58 (__TEXT,__text) external _main
(undefined) external _printf (from libSystem)
oso_prefix (no symlinks) ld_classic:
0000000000000000 (?) non-external
0000000000000000 (?) non-external /var/folders/_0/_vrx1th904x4bsf1c0_w4bhw00g80m/T/linker_path_bug/srcs/
0000000000000000 (?) non-external main.c
0000000066e86ece (?) non-external build_outputs/main.o
0000000100003f58 (__TEXT,__text) non-external
0000000100003f58 (?) non-external _main
0000000000000034 (?) non-external
0000000100003f58 (__TEXT,__text) non-external
0000000000000000 (?) non-external
0000000100000000 (__TEXT,__text) [referenced dynamically] external __mh_execute_header
0000000100003f58 (__TEXT,__text) external _main
(undefined) external _printf (from libSystem)
oso_prefix (.o file symlinks) ld:
0000000000000000 (?) non-external
0000000000000000 (?) non-external /var/folders/_0/_vrx1th904x4bsf1c0_w4bhw00g80m/T/linker_path_bug/srcs/
0000000000000000 (?) non-external main.c
0000000066e86ece (?) non-external /private/var/folders/_0/_vrx1th904x4bsf1c0_w4bhw00g80m/T/linker_path_bug/build_outputs/main.o
0000000100003f58 (__TEXT,__text) non-external
0000000100003f58 (?) non-external _main
0000000000000034 (?) non-external
0000000100003f58 (__TEXT,__text) non-external
0000000000000000 (?) non-external
0000000100000000 (__TEXT,__text) [referenced dynamically] external __mh_execute_header
0000000100003f58 (__TEXT,__text) external _main
(undefined) external _printf (from libSystem)
oso_prefix (.o file symlinks) ld_classic:
0000000000000000 (?) non-external
0000000000000000 (?) non-external /var/folders/_0/_vrx1th904x4bsf1c0_w4bhw00g80m/T/linker_path_bug/srcs/
0000000000000000 (?) non-external main.c
0000000066e86ece (?) non-external ./build_outputs/main.o
0000000100003f68 (__TEXT,__text) non-external
0000000100003f68 (?) non-external _main
0000000000000034 (?) non-external
0000000100003f68 (__TEXT,__text) non-external
0000000000000000 (?) non-external
0000000100000000 (__TEXT,__text) [referenced dynamically] external __mh_execute_header
0000000100003f68 (__TEXT,__text) external _main
(undefined) external _printf (from libSystem)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment