-
-
Notifications
You must be signed in to change notification settings - Fork 610
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
Fix issue 15574 - wrong order of link arguments #8172
Conversation
This essentially places *.a arguments before the -l and -L switches in
the linker command line.
This allows to link applications that link against a static archive *.a
that depends on -l lib switches.
Such dependency scheme is typical of the following situation:
- have a D package that contains binding to a C library.
- this D package is itself built as a static library (libdpackage.a).
- the C library is built in the same build process as a static library
(pathtoClib/libclib.a)
- dmd is invoked in the following way:
$ dmd ... libdpackage.a -L-LpathtoClib -L-lclib
Currently dmd reorders arguments and places *.a after -l linker switches
which causes link errors if the -l points to a static library.
This is especially useful with Dub, which can be configured to probe for
the C library, and build it as a static lib if not found system-wide.
In both cases, the C library is provided with "libs" json entry.
So this is not about keeping relative order of linker arguments, it is
about providing an order of linker arguments that is more sound than
the current one.
|
Thanks for your pull request and interest in making D better, @rtbo! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
|
|
I have here a simple test case: git clone https://github.com/rtbo/dmd_link_args_order
cd dmd_link_args_order
make appFails to link with dmd from master, links with this PR. |
|
@rtbo have a look at the existing bash scripts in the testsuite for examples on how this can be added to testsuite. |
|
The documentation failure is unrelated to this PR. |
|
|
||
| ${DMD} -m${MODEL} -lib -of${D_LIB} ${D_FILE} | ||
|
|
||
| ${DMD} -m${MODEL} -of${APP} ${APP_FILE} -I${TEST_DIR} ${D_LIB} -L-L${TEST_DIR} -L-lcsquare |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also run the executable to make sure that everything is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. (and squashed)
|
|
||
| ${DMD} -m${MODEL} -of${APP} ${APP_FILE} -I${TEST_DIR} ${D_LIB} -L-L${TEST_DIR} -L-lcsquare | ||
|
|
||
| ${APP} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be best if you could check that the application actually runs correctly i.e. it finished with exit code 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't the test fail if a command returns non-zero?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are correct. sorry for the confusion
|
@rtbo I added the |
|
@rtbo This pull request introduced a regression: |
This essentially places *.a arguments before the -l and -L switches in
the linker command line.
This allows to link applications that link against a static archive *.a
that depends on -l lib switches.
Such dependency scheme is typical of the following situation:
(pathtoClib/libclib.a)
Currently dmd reorders arguments and places *.a after -l linker switches
which causes link errors if the -l points to a static library.
This is especially useful with Dub, which can be configured to probe for
the C library, and build it as a static lib if not found system-wide.
In both cases, the C library is provided with "libs" json entry.
So this is not about keeping relative order of linker arguments, it is
about providing an order of linker arguments that is more sound than
the current one.