[lld] [lld][ELF] Enable link script to support absolute path matching (PR #156353)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 4 02:20:38 PDT 2025


mykouHW wrote:

> I found the description difficult to follow.
> 
> > When input files use absolute paths, the matching results from mc lld do not meet expectations.
> 
> Can you say what your expectations are and why?
> 
> If I've understood your patch correctly, you expect lld to match the file part of `file.o(section)` with an object with a filename of `/path/to/file.o`
> 
> When I look at https://sourceware.org/binutils/docs/ld/Input-Section-Basics.html I can't see anything that says that when a full path is given the linker is expected to extract the filename. I think the recommended pattern in this case is `*file.o(section)`
> 
> Trying to make a similar example with GNU ld, I got an error message: `ld: cannot find foo.o: No such file or directory`
> 
> So we definitely have a discrepancy between GNU ld and lld, but if we think it is important I'd prefer that we fix it to match GNU ld behaviour. I think there could be problems with automatically discarding path information, particularly when there are multiple object files with the same name, but different paths `path1/foo.o` `path2/foo.o`
> 
> As an aside mc lld, doesn't exist as a name, it is just lld.

Thanks for your comment!

When the absolute path is used to input the object file in the ld.lld command, the expectation of "merging bar and foo into the .goo section" in the linker script is not achieved.

For example, if use the command like this:
`ld.lld main.o %t/foo.o %t/bar.o -T script.ld -o main_abs.o -Map=main_abs.map`,
 the sections .text_foo and .text_bar will be set as OrphanSection and no .goo section will be generated.
<img width="824" height="364" alt="abs" src="https://github.com/user-attachments/assets/26766c8c-4aac-4177-ae5b-ffc171ba7273" />


However, if use the command like this:
`ld.lld main.o foo.o bar.o -T script.ld -o main_abs.o -Map=main_abs.map`,
no .text_foo and .text_bar sections will be generated, only a .goo section containing bar and foo will be generated.
<img width="800" height="598" alt="rel" src="https://github.com/user-attachments/assets/d831745b-a8a4-4b30-9ed4-55eb2d64adeb" />


https://github.com/llvm/llvm-project/pull/156353


More information about the llvm-commits mailing list