Skip to content

ld64.lld: Linker doesn't create empty text section for shared library without any code #72404

Open
@lewurm

Description

@lewurm

... which sounds reasonable, but breaks an assumption in install_name_tool:

$ cat myfoobar.c
int foobar(int a, int b) {
    return a + b;
}
$ clang -v -dynamiclib myfoobar.c -o liba.dylib
$ clang -v -dynamiclib -o libdummy-ld64.dylib -L`pwd` -la
$ clang -v -dynamiclib -o libdummy-lld.dylib -fuse-ld=/path/to/ld64.lld -L`pwd` -la
$ otool -l libdummy-ld64.dylib
libdummy-ld64.dylib:
Load command 0
      cmd LC_SEGMENT_64
  cmdsize 152
  segname __TEXT
   vmaddr 0x0000000000000000
   vmsize 0x0000000000004000
  fileoff 0
 filesize 16384
  maxprot 0x00000005
 initprot 0x00000005
   nsects 1
    flags 0x0
Section
  sectname __text
   segname __TEXT
      addr 0x0000000000004000
      size 0x0000000000000000
[...]
$ otool -l libdummy-lld.dylib
libdummy-lld.dylib:
Load command 0
      cmd LC_SEGMENT_64
  cmdsize 72
  segname __TEXT
   vmaddr 0x0000000000000000
   vmsize 0x0000000000004000
  fileoff 0
 filesize 16384
  maxprot 0x00000005
 initprot 0x00000005
   nsects 0
    flags 0x0
[...]
$ install_name_tool -id @rpath/liba.dylib libdummy-ld64.dylib # works fine
$ install_name_tool -id @rpath/liba.dylib libdummy-lld.dylib
error: /Applications/Xcode15beta8.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: changing install names or rpaths can't be redone for: libdummy-lld.dylib (for architecture arm64) because larger updated load commands do not fit (the program must be relinked, and you may need to use -headerpad or -headerpad_max_install_names)

The error message is a bit misleading. If I understand correctly install_name_tool just assumes that __text exists:

Using -Wl,-add_empty_section,__TEXT,__text fixes the problem, but I think it would be nice if ld64.lld has the same behaviour in that area.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions