-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add tools.build:linker_scripts conf variable #12854
Add tools.build:linker_scripts conf variable #12854
Conversation
Adds a conf variable for supplying linker scripts to the linker with `-T`. Includes support for CMakeToolchain, AutotoolsToolchain, and MesonToolchain.
3078a4c
to
4a86440
Compare
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.
Thanks @jwillikers for your contribution.
I think it seems this could make sense, and seems reasonable.
I'd like to understand a bit better your comments:
Common use cases for this include using a different linker script for a separate bootloader application.
Currently, a project which sets a default linker script in exelinkflags must overwrite all of the existing exelinkflags in order to change the linker script for a particular package.
This is prone to copy and paste errors and makes it more difficult to safely compose profiles.
What do you mean? Wouldn't it be equivalent? Something like:
pkg1*:tools.build:exelinkflags+="-T mybooloader1"
pkg2*:tools.build:exelinkflags+="-T myloaderboot2"
# and
pkg1*:tools.build:linker_scripts=["mybootloader1"]
pkg2*:tools.build:linker_scripts=["myloaderboot2"]
It would be interesting to know better the pain that this aims to alleviate.
@memsharded It would be that simple if the only
By having a separate conf variable for the linker scripts, this becomes:
My copy-paste error was related to me duplicating these profiles for a very similar MCU. |
I'll ping @kammce since I know he has shown interest in this feature in the past. He might have something to add to the conversation. |
Hi @jwillikers I think the problem that you are describing is not really happening. I have done a test in #12862 to validate it. These are the profiles: profile1:
profile2:
Applying it to different packages works fine:
|
@memsharded Yes, your stated case works in my experience as well. My use case is slightly different than that because I have a linker script which is used in the default case for all packages:
Later in the profile, I override the default linker script for two specific packages:
Unfortunately, I can't just append at this point since the default linker script has already been added to I use a linker script for all cases for convenience and if I remember correctly, it's necessary for test packages to link successfully. For instance, if my package uses |
Ok, perfect, thanks very much @jwillikers, that fully clarifies now the use case. |
So I'm still learning the different ways to use Conan so this may come off as a dumb question. Is there a way with a conan recipe to produce multiple package targets. Like, installing a package Is it a choice that the user can use the conf variable or not? Because there are many times when a user will want to use their own linker script rather than the one handed to them. Most times to segment out sections of RAM or Flash for particular types of data. So long as we have 1 package multiple subpackages and a way to opt in/out of using the package provided linker script, then this feature would be great. This would definitely help get rid of the copy & paste problem I've been dealing with. If I have a ton of apps using a library, and I want to use the same default linker script for everyone, I have to copy it N number of times |
Hi @kammce
I am not sure what you mean exactly, but it sounds that you want to extend the Conan settings.yml (https://docs.conan.io/en/latest/extending/custom_settings.html), to define different micros, as each one might result in different binaries as you describe. Then in the profile you would define the custom setting value, and that will give you a different package_id. This is the "binary model".
I know nothing about the linker scripts, but yes, the
I don't fully get it either. Maybe @jwillikers can give some more insights given he has the knowledge both about Conan and these linker scripts for micros. |
@kammce Conan doesn't really have a concept for subpackages, so you would want to actually create individual builds of such a package for each microcontroller you want to target. I'm imagining your use case would be to create a HAL library like I'm primarily controlling linker scripts through profiles at this point, outside of any package. If you'd like such a HAL library to configure the linker scripts for consumers' projects, they would need to consume it as a I believe it's possible to opt out or override linker scripts provided through profiles,
|
@jwillikers Okay understood. For profiles, this seems like a good idea then. I'll look into settings/options for my driver libraries for setting up linker scripts. |
Sorry, closed by accident by another PR, re-opening |
Changelog: Feature: Adds a conf variable for supplying linker scripts to the linker using the
-T
flag.Docs: conan-io/docs#2887
Fixes #9789
Linker scripts are required for bare metal development, i.e. when targeting microcontrollers.
They communicate the memory layout of the chip to the linker since there is no operating system available to handle such details.
Although
tools.build:exelinkflags
provides a mechanism that could be used to pass this flag, it is not as convenient as a dedicated option for something fundamental to bare metal development nor is it sufficient for use cases requiring more flexibility.For instance, a project which wants to share a common set of linker flags for a variety of applications targeting the same microcontroller platform may want to modify the linker script on a per-application basis.
Common use cases for this include using a different linker script for a separate bootloader application.
Currently, a project which sets a default linker script in
exelinkflags
must overwrite all of the existingexelinkflags
in order to change the linker script for a particular package.This is prone to copy and paste errors and makes it more difficult to safely compose profiles.
A dedicated
linker_scripts
option also makes it possible for Conan to handle any peculiarities related to handling filesystem paths.This PR includes support for the
tools.build:linker_scripts
conf variable in the CMakeToolchain, AutotoolsToolchain, and MesonToolchain toolchains.Here are some notes on compatibility.
This conf option only works for GNU-compatible linkers that support the
-T
linker script argument which includesld
,gold
,lld
, and themingw-w64
ld
.Since Conan doesn't have configuration options for the linker, these linkers correspond to the Clang, GCC, and mingw compilers.
The linker for Clang on Windows is compatible with the MSVC++ linker
link.exe
, so it does not support this option.In general, the linker on most Unix systems is likely to support the
-T
flag.develop
branch, documenting this one.Note: By default this PR will skip the slower tests and will use a limited set of python versions. Check here how to increase the testing level by writing some tags in the current PR body text.