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

Moved link time build options out of compile time options #23

Merged
merged 1 commit into from
Feb 12, 2024

Conversation

speedy-h
Copy link
Contributor

Moved link time build options out of compile time options

Issue
A link time option is set in the compile time options and has no effect, the file is not stripped and remains a larger size.

I ran with cmake version 3.23.1 and compiler GNU 9.4.0

To repeat:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make VERBOSE=1
ls -l libisotp.so 
file libisotp.so

Current code:

-rwxr-xr-x 1 xxxxx xxxxx 16800 Feb  9 12:43 libisotp.so
libisotp.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=bb5eaf2d1b5224dc699c21a17cf76d283f06cbef, not stripped

Running after PR change:

-rwxr-xr-x 1 xxxxx xxxxx 14472 Feb  9 12:43 libisotp.so
libisotp.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=5d5c9d947e2c6969e47f7ecae5bf1414d9878751, stripped

The file is smaller and stripped.

No change for the static library build.

Other points to note
The PR used target_link_libraries which is available in cmake version 3.10. If you're happy to move the cmake version up to 3.13, target_link_options may be better.
https://cmake.org/cmake/help/latest/command/target_link_options.html

This issue was originally noticed when compiling with clang (version 13.0.1) which will fail the build with the following error:

[ 50%] Building C object CMakeFiles/isotp.dir/isotp.c.o
clang: error: argument unused during compilation: '-s' [-Werror,-Wunused-command-line-argument]

@speedy-h
Copy link
Contributor Author

Below is the make output showing th -s option passed during compiling, but not linking which is resolved in this PR. -O2 is passed at compile time, but -O3 is used by cmake when in release build. During compile, the last optimisation level specified is used, -O2. At link only -O3 is present.

[ 50%] Building C object CMakeFiles/isotp.dir/isotp.c.o
/usr/bin/cc -Disotp_EXPORTS -I/home/xxxxx/temp/isotp-c -O3 -DNDEBUG -fPIC -fPIC -Werror -Wall -Wno-unknown-pragmas -O2 -s -MD -MT CMakeFiles/isotp.dir/isotp.c.o -MF CMakeFiles/isotp.dir/isotp.c.o.d -o CMakeFiles/isotp.dir/isotp.c.o -c /home/xxxxx/temp/isotp-c/isotp.c
[100%] Linking C shared library libisotp.so
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/isotp.dir/link.txt --verbose=1
/usr/bin/cc -fPIC -O3 -DNDEBUG -shared -Wl,-soname,libisotp.so -o libisotp.so CMakeFiles/isotp.dir/isotp.c.o 

@SimonCahill
Copy link
Owner

Hi there!

Thanks for the contribution!
Seems I completely oversaw that.

Changes seem good and workflows pass. LGTM.

I don't have anything to test currently, but as you've not changed any of the logic, I don't see any issues that may arise. I'll merge it with the master branch.

@SimonCahill SimonCahill merged commit 34fa61a into SimonCahill:master Feb 12, 2024
1 check passed
@speedy-h speedy-h deleted the link_option branch March 12, 2024 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants