<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/119584>119584</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [LLD] lld linker script does not support library: or :file file descriptor patterns
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lld
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          smithp35
      </td>
    </tr>
</table>

<pre>
    This was found by an internal project while trying to migrate from a GNU toolchain to a LLVM based toolchain.

The GNU ld manual https://sourceware.org/binutils/docs/ld/Input-Section-Basics.html has the following section:
```
You can also specify files within archives by writing a pattern matching the archive, a colon, then the pattern matching the file, with no whitespace around the colon.

‘archive:file’
matches file within archive

‘archive:’
matches the whole archive

‘:file’
matches file but not one in an archive
``` 
LLD will support `archive:file` but it does not support `archive:` or `:file`.

For example: 
app.s
```
        .text
        .global _start
        .type _start, %function
        .global foo
_start: call foo
```
lib.s
```
        .text
        .global foo
        .type foo, %function
foo:    nop
``` 
app.ld
```
SECTIONS {
  lib : { lib.a:(*.text) }      /* Expect lib.a(lib.o):(.text) */
  app : { :app.o(*.text) } /* Expect app.o(.text) */
  all : { *(.text) } /* Expect no matches */
}
```
clang --target=x86_64 -c app.s lib.s
llvm-ar -rcs lib.a lib.o
ld.ldd app.o lib.a --script=app.ld
```
             VMA              LMA     Size Align Out     In      Symbol
               0                0        9     4 all
               0                0        5     4         app.o:(.text)
               0                0        0     1                 _start
               8                8        1     4         lib.a(lib.o):(.text)
               8                8        0     1                 foo
```
We can see the .text has been matched by all. GNU ld matches as we would expect:
ld.bfd app.o lib.a --script=app.ld --print-map
```
lib             0x0000000000000000        0x1
 lib.a:(*.text)
 .text          0x0000000000000000        0x1 lib.a(lib.o)
                0x0000000000000000                foo

app             0x0000000000000004        0x5
 :app.o(*.text)
 .text          0x0000000000000004        0x5 app.o
                0x0000000000000004                _start
```

There is a workaround for the library pattern by using `library:*` but I can't think of one for the `:file` 
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVl1vozoT_jXOzYiImHxxkQu62byqlN296L57dK5Wxpjg08FGtmma8-uPbKBpSNptUVXIfDwzfjz2DLNWHpQQG7K4I4vthLWu0mZja-mqJllMcl2cNj8raeHILJS6VQXkJ2AKpHLCKIbQGP2P4A6OlUQBzpykOoDTUMuDYU5AaXQNDP73_f_gtEZeMam8nsF-_-sb5MyK4qyZkjgjcfazEsEDC6iZahlC5VxjSZIRuiN0Z3VruDgyI6baHAjd5VK1TqIldFdo7l9YELq7V03rogfBndQqumNWcjutXI1QMQuuElBqRH30OdvOyseIM7KM-784-1u3wJkChlaDbQSX5QlKicLCUbpKKmCGV_JJWM_N0Ujn4Rg0zHmOoGaOV4GVSgymhH4BBlyjVv7TVUIF9U0fH8tb-WigtKfaCdsw7uHCnnirANbzR75Sso5Juh7CJVkA6cUpibMQQdgAPlrHmxi3_H3oY6VRvOH9p9B560BpB1oJ8ClcZDHsApA42--3cJSIYNum0cYBWcaj5S3jACcdFFrYAHvT2Btq42Vnz565nTYgnlndoDf0cVnTTO2oJKB_pk48u9e_D6hzhvDbOmYuFO7UiEFMvwChi7JVXcFdu5dakzjrrZMMOMNB-DoLlPmnM-tQLtPysqucvDAJhko3473wnGAxCv3w9cvP-x_fH4Cs7kIMlDkEEld3_nvKwvldE5p12dEUyGrbZRLOdQZfnxt_mXTWdO3fmtC0czx70XAP-BisaV5ikCQkpm_EuIQfrG4CIp4B6WXYKyClYSjmFwiy2o6I4cjUAaLIMXMQjiTb5_Xy93IOEQ-ZWBg2EvGpjpiByPBOyKBjIM6wmGJRdJn3qiiy3MjGA97cD3j9_Pp2-Rv2veBB_isgQ3lQ8KN1QXSvOpOHU51rHCMBxPCWIA3_557Ez7gterfh6fbnYs8_A9d9zMb661PZP-ux4YtgNkrs_br8DPJbOV6f8r9E6D5WiHDXhmChfeVC9I1CdF0ZcXruml1VMgtHAUf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