Diff Detail
Unit Tests
Event Timeline
This is probably not a good idea. See https://github.com/llvm/llvm-project/issues/60203#issuecomment-1407532083
I agree with your comment in https://github.com/llvm/llvm-project/issues/60203#issuecomment-1407532083, But I still think my patch is worth to be applied.
Since you mentioned It's not a problem to have multiple -Tdata=. The last wins. But what will happen if both a linker script and a -Wl,-Tdata are specified? ASFAIK, the command line option will win.
But the default "-Tdata" is added according to each specific AVR device SRAM layout (https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/AVR.cpp#L35).
My opinion is:
- We should add a default SRAM address to the linker, if user does not specify any link options. This is current behaviour of clang's main branch.
- If the user explictly specifies a linker scrpit, we should follow the user's willing, and do not decide the SRAM address for him.
clang/lib/Driver/ToolChains/AVR.cpp | ||
---|---|---|
499–500 | I have added comment about why we need this change, it has nothing to do with https://github.com/llvm/llvm-project/issues/60203. |
OK. If this doesn't add -Tdata= driver options, I'm fine with it.
But why is default -Tdata added in the first place?
Most linker scripts are added as -Wl,-T,a.lds (-Wl, values are opaque to the driver), so the driver cannot really know whether a linker script is used.
So how about change to
- move the default -Tdata to a later position.
- clang driver just checks -T but omits -Wl, this can not 100% fix the issue, but at least improve it. Current most users are from avr-gcc, who have get used to -T.
A good solution is using default linker script provided by the avr-libc, which will be overwritten by user's explicit specification.
I will do that solution in a different patch, it needs more extra work. Currently we just guarantee avr-gcc users's -T option will not be broken.
clang/lib/Driver/ToolChains/AVR.cpp | ||
---|---|---|
544 | Just moving the default -T from previous position to here, without any change. |
I think checking whether there is a linker script in any way is not a right solution.
GNU ld supports -dT which lld doesn't support. A linker script can be used without a -T/-dT option as well (it gets appended).
Any chance to remove -Tdata= and require the user to specify a -Tdata=?
Newer avr-gcc's solution is adding a default linker script (provided by binutils, locates at $binutils-gdb/ld/scripttempl/avr.sc). And user can specifies his own one, which will win against the default one.
I will remove the default -Tdata, and append a default -Tavr.sc along with several --defsym (required by avr.sc).
How do you think about this solution ?
How does avr-gcc know whether the user provides a linker script?
I really don't like adding a default -Tdata= when it can interfere with common uses of specifying a linker script. In these situations drivers not adding default options is usually better than guessing the user intention.
If the use case is somewhat strange, we can document it.
My option,
- we remove default -Tdata
- we add a default -T avr.sc (provided by bintuils as default) at an early position of avr-ld's options.
- If user specified -T xx.lds, append user's at an late position, then user's will win, the default will lose.
I have a question. linux-x86 has its default linker script, which can also be specified by user. How does clang driver implement that? Could you please show me where clang handle this ?
I hope avr also follow this logic. User's willing go first, then default linker script.
I have added comment about why we need this change, it has nothing to do with https://github.com/llvm/llvm-project/issues/60203.