Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CustomMain NativeAot test doesn't support cross-arch compilation #82320

Closed
sbomer opened this issue Feb 17, 2023 · 5 comments
Closed

CustomMain NativeAot test doesn't support cross-arch compilation #82320

sbomer opened this issue Feb 17, 2023 · 5 comments

Comments

@sbomer
Copy link
Member

sbomer commented Feb 17, 2023

The testcase added in #81873 doesn't currently work when cross-building tests from x64 for arm64.

When I do a cross-build of the tests, this is the command-line that gets used to compile the native object:
cd /home/svbomer/src/runtime/artifacts/tests/coreclr/obj/linux.arm64.Release/Native/nativeaot/CustomMain && /usr/bin/clang++-15 -DDISABLE_CONTRACTS -DHOST_64BIT -DHOST_AMD64 -DHOST_UNIX -DNDEBUG -DTARGET_64BIT -DTARGET_AMD64 -DTARGET_LINUX -DTARGET_UNIX -DURTBLDENV_FRIENDLY=Retail -D_FILE_OFFSET_BITS=64 -I/home/svbomer/src/runtime/src/native -I/home/svbomer/src/runtime/src/tests/Common/Platform -O3 -DNDEBUG -fPIC -O3 -g -Wall -Wno-null-conversion -fno-omit-frame-pointer -fms-extensions -fwrapv -fstack-protector-strong -Werror -Wno-unused-variable -Wno-unused-value -Wno-unused-function -Wno-tautological-compare -Wno-unknown-pragmas -Wimplicit-fallthrough -Wno-invalid-offsetof -Wno-unused-but-set-variable -ffp-contract=off -fno-rtti -Wno-unknown-warning-option -ferror-limit=4096 -Wno-unused-private-field -Wno-constant-logical-operand -Wno-pragma-pack -Wno-incompatible-ms-struct -Wno-reserved-identifier -Wno-unsafe-buffer-usage -Wno-single-bit-bitfield-constant-conversion -Wno-cast-function-type-strict -fsigned-char -fvisibility=hidden -ffunction-sections -std=gnu++11 -MD -MT nativeaot/CustomMain/CMakeFiles/CustomMainNative.dir/CustomMainNative.cpp.o -MF CMakeFiles/CustomMainNative.dir/CustomMainNative.cpp.o.d -o CMakeFiles/CustomMainNative.dir/CustomMainNative.cpp.o -c /home/svbomer/src/runtime/src/tests/nativeaot/CustomMain/CustomMainNative.cpp

Notice the -DTARGET_AMD64. The test gets compiled for amd64 even though I am asking to build for arm64:

ROOTFS_DIR=`pwd`/../crossrootfs/arm64 ./src/tests/build.sh -arm64 nativeaot Release test nativeaot/CustomMain/CustomMain.csproj

which results in downstream errors later in the build:

/usr/bin/aarch64-linux-gnu-ld: /home/svbomer/src/runtime/artifacts/tests/coreclr/linux.arm64.Release/nativeaot/CustomMain/CustomMain/libCustomMainNative.a(CustomMainNative.cpp.o): Relocations in generic ELF (EM: 62)
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Feb 17, 2023
@ghost
Copy link

ghost commented Feb 17, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

The testcase added in #81873 doesn't currently work when cross-building tests from x64 for arm64.

When I do a cross-build of the tests, this is the command-line that gets used to compile the native object:
cd /home/svbomer/src/runtime/artifacts/tests/coreclr/obj/linux.arm64.Release/Native/nativeaot/CustomMain && /usr/bin/clang++-15 -DDISABLE_CONTRACTS -DHOST_64BIT -DHOST_AMD64 -DHOST_UNIX -DNDEBUG -DTARGET_64BIT -DTARGET_AMD64 -DTARGET_LINUX -DTARGET_UNIX -DURTBLDENV_FRIENDLY=Retail -D_FILE_OFFSET_BITS=64 -I/home/svbomer/src/runtime/src/native -I/home/svbomer/src/runtime/src/tests/Common/Platform -O3 -DNDEBUG -fPIC -O3 -g -Wall -Wno-null-conversion -fno-omit-frame-pointer -fms-extensions -fwrapv -fstack-protector-strong -Werror -Wno-unused-variable -Wno-unused-value -Wno-unused-function -Wno-tautological-compare -Wno-unknown-pragmas -Wimplicit-fallthrough -Wno-invalid-offsetof -Wno-unused-but-set-variable -ffp-contract=off -fno-rtti -Wno-unknown-warning-option -ferror-limit=4096 -Wno-unused-private-field -Wno-constant-logical-operand -Wno-pragma-pack -Wno-incompatible-ms-struct -Wno-reserved-identifier -Wno-unsafe-buffer-usage -Wno-single-bit-bitfield-constant-conversion -Wno-cast-function-type-strict -fsigned-char -fvisibility=hidden -ffunction-sections -std=gnu++11 -MD -MT nativeaot/CustomMain/CMakeFiles/CustomMainNative.dir/CustomMainNative.cpp.o -MF CMakeFiles/CustomMainNative.dir/CustomMainNative.cpp.o.d -o CMakeFiles/CustomMainNative.dir/CustomMainNative.cpp.o -c /home/svbomer/src/runtime/src/tests/nativeaot/CustomMain/CustomMainNative.cpp

Notice the -DTARGET_AMD64. The test gets compiled for amd64 even though I am asking to build for arm64:

ROOTFS_DIR=`pwd`/../crossrootfs/arm64 ./src/tests/build.sh -arm64 nativeaot Release test nativeaot/CustomMain/CustomMain.csproj

which results in downstream errors later in the build:

/usr/bin/aarch64-linux-gnu-ld: /home/svbomer/src/runtime/artifacts/tests/coreclr/linux.arm64.Release/nativeaot/CustomMain/CustomMain/libCustomMainNative.a(CustomMainNative.cpp.o): Relocations in generic ELF (EM: 62)
Author: sbomer
Assignees: -
Labels:

area-NativeAOT-coreclr

Milestone: -

@sbomer
Copy link
Member Author

sbomer commented Feb 17, 2023

Same issue for the SharedLibrary nativeaot test:
cd /home/svbomer/src/runtime/artifacts/tests/coreclr/obj/linux.arm64.Release/Native/nativeaot/SmokeTests/SharedLibrary && /usr/bin/clang++-15 -DDISABLE_CONTRACTS -DHOST_64BIT -DHOST_AMD64 -DHOST_UNIX -DNDEBUG -DTARGET_64BIT -DTARGET_AMD64 -DTARGET_LINUX -DTARGET_UNIX -DURTBLDENV_FRIENDLY=Retail -D_FILE_OFFSET_BITS=64 -I/home/svbomer/src/runtime/src/native -I/home/svbomer/src/runtime/src/tests/Common/Platform -O3 -DNDEBUG -fPIE -fPIE -O3 -g -Wall -Wno-null-conversion -fno-omit-frame-pointer -fms-extensions -fwrapv -fstack-protector-strong -Werror -Wno-unused-variable -Wno-unused-value -Wno-unused-function -Wno-tautological-compare -Wno-unknown-pragmas -Wimplicit-fallthrough -Wno-invalid-offsetof -Wno-unused-but-set-variable -ffp-contract=off -fno-rtti -Wno-unknown-warning-option -ferror-limit=4096 -Wno-unused-private-field -Wno-constant-logical-operand -Wno-pragma-pack -Wno-incompatible-ms-struct -Wno-reserved-identifier -Wno-unsafe-buffer-usage -Wno-single-bit-bitfield-constant-conversion -Wno-cast-function-type-strict -fsigned-char -fvisibility=hidden -ffunction-sections -std=gnu++11 -MD -MT nativeaot/SmokeTests/SharedLibrary/CMakeFiles/SharedLibraryDriver.dir/SharedLibrary.cpp.o -MF CMakeFiles/SharedLibraryDriver.dir/SharedLibrary.cpp.o.d -o CMakeFiles/SharedLibraryDriver.dir/SharedLibrary.cpp.o -c /home/svbomer/src/runtime/src/tests/nativeaot/SmokeTests/SharedLibrary/SharedLibrary.cpp

This one fails not when building tests (since this just builds the shared library, and doesn't need to statically link it), but when running the:

/root/helix/work/correlation/nativeaottest.sh: line 15: /root/helix/work/workitem/e/nativeaot/SmokeTests/SharedLibrary/SharedLibrary//native/SharedLibrary: cannot execute binary file: Exec format error

And similar for the Pinvoke test, which compiles a native shared library. This one fails to load the shared lib dependency at runtime:

Unhandled Exception: System.DllNotFoundException: Unable to load shared library 'PInvokeNative' or one of its dependencies. In order to help diagnose loading problems, consider using a tool 

@am11
Copy link
Member

am11 commented Feb 18, 2023

ROOTFS_DIR=pwd/../crossrootfs/arm64 ./src/tests/build.sh -arm64 nativeaot Release test nativeaot/CustomMain/CustomMain.csproj

Missing -cross argument? Try

ROOTFS_DIR=/crossrootfs/arm64 ./src/tests/build.sh -cross -arm64 nativeaot Release test nativeaot/CustomMain/CustomMain.csproj

(-cross maps to /p:CrossBuild=true)

@am11
Copy link
Member

am11 commented Feb 18, 2023

Notice the -DTARGET_AMD64.

btw, this define by itself is not the indicator of cross compilation. In the context of clang (as linker driver) command line, the argument for cross target to look for is -target.

@agocke agocke added this to AppModel Mar 6, 2023
@sbomer
Copy link
Member Author

sbomer commented May 3, 2023

Seems this was a user error - this now seems to work if I pass the right -cross argument.

@sbomer sbomer closed this as completed May 3, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label May 3, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

2 participants