The -image-base option allows for overriding the base address.
Details
Diff Detail
Event Timeline
This patch sets the process start address, but is this what -Ttext-segment should do? GNU ld's manual page says that the option sets the start address of the text segment. So it should set the start address of .text segment, no?
Yes it is, because text segment is not the same thing as .text section, text segment really means the base address, at least that's the semantics as implemented by both ld and gold.
I think doing it is valid only for ld.gold because the linker layouts a executable segment at beginning of a file image. Our segment layout is not the same as GNU gold -- we actually layout a read-only data segment at beginning of a file. So I think just setting the base pointer is not enough for us to handle -Ttext-segment.
There are two issues here. The first is correctness, and you're right that for lld -Trodata-segment as an option for setting the start address would be better since lld puts rodata segment at the beginning. The other is compatibility, as large number of existing build scripts use -Ttext-segment as an option for setting the start address, irrespective of which linker is being used.
In our use case, we would like to have an option to set the start address in lld. Would it be fine with you if I rename the option to -image-base? This option is already supported by BFD ld, even though it's only used for PE targets, and OS X ld also has a similar option -image_base. Alternatively we could use a completely different name.
In the future, if it's needed by other users for backwards compatibility, we can decide whether this option should be an alias for -Trodata-segment or -Ttext-segment, or other option.
Ed, do you know if the uses of -Ttext is FreeBSD are trying to set the
address of the text segment or just control the the lowest address in
the binary (i.e., set the address of the first segment)?
Cheers,
Rafael
ELF/Config.h | ||
---|---|---|
104 | Don't give it an initial value in here. | |
ELF/Driver.cpp | ||
534 | Always set VAStart in here, since this is already looking at Target-> it may as well have an else to set it to the target default. | |
ELF/Writer.cpp | ||
1129 | And with Config->VAStart always having the correct value you don't need this function. |
Once we add a new option, we have to support it basically forever, so I'd like to be conservative. First of all, why do you want this option? What program are you trying to link with LLD, and why the program needs this option?
ELF/Config.h | ||
---|---|---|
104 | Move this after EntryAddr. |
In general, this is an option supported by all existing linkers and it's used by the existing software; having to use a custom linker script just to change the start address is a bit of an overkill.
In our case, we would like to use lld as our system linker, but in our system the lowest available start address is different from the default start address used by lld. Having an option to set the start address allows us to pass this option to the linker from our Clang toolchain driver and avoid the use of linker script.
LGTM. I think this option makes sense. It seems to me that --image-base feels a bit too Windows-ish name, but I can't think of a better name, so I'm okay with it.
Please make the following changes before commiting.
ELF/Config.h | ||
---|---|---|
104 | Did you do this? | |
ELF/Driver.cpp | ||
534 | Please move this code to readConfigs. |
ELF/Driver.cpp | ||
---|---|---|
534 | That's a problem; I need Target to exists to read PageSize and VAStart, but Target is only created in link which is executed after readConfigs. Shall I move Target initialization out from link before readConfigs? |
ELF/Driver.cpp | ||
---|---|---|
534 | Ah, okay, then keeping this code here makes sense. Sorry about that! |
Always set VAStart in here, since this is already looking at Target-> it may as well have an else to set it to the target default.