Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lld] LLD handles strings and their substrings in .rodata sections differently than the gnu ld linker. #121182

Open
Zhenhang1213 opened this issue Dec 27, 2024 · 2 comments
Labels

Comments

@Zhenhang1213
Copy link
Contributor

Zhenhang1213 commented Dec 27, 2024

demo:

#include <stdio.h>

void func1() {
    printf("Hello, World!\n");
}

#include <stdio.h>

void func2() {
    printf("123 Hello, World!\n");
}

int main(){
        func1();
        func2();
        return 0;
}

clang demo.c -o a.out -fuse-ld=ld
clang demo.c -o a.out -fuse-ld=lld

lld:

Contents of section .rodata:
 05f8 01000200 48656c6c 6f2c2057 6f726c64  ....Hello, World
 0608 210a0031 32332048 656c6c6f 2c20576f  !..123 Hello, Wo
 0618 726c6421 0a00                        rld!..

ld:

Contents of section .rodata:
 07ec 01000200 31323320 48656c6c 6f2c2057  ....123 Hello, W
 07fc 6f726c64 210a00                      orld!..

GNU ld version is 2.41

for the codesize, lld could support this feature?

@github-actions github-actions bot added the lld label Dec 27, 2024
@Andarwinux
Copy link
Contributor

-Wl,-O2

@Zhenhang1213
Copy link
Contributor Author

-Wl,-O2

Thank you very much. It'll help me more. By the way, I have a more question, .strtab section has more duplicate symbols, and they are ABI symbols , like $d $x, is there any
option align to ld?
lld:

String dump of section '.strtab':
  [     1]  $x.0
  [     6]  $d.1
  [     b]  $d.2
  [    10]  $d.3
  [    15]  $d.4
  [    1a]  $d.5
  [    1f]  $d.6
  [    24]  $d.7
  [    29]  abi-note.c
  [    34]  __abi_tag
  [    3e]  $d.0
  [    43]  $d.1
  [    48]  $d.2
  [    4d]  $d.3
  [    52]  $d.4
  [    57]  $d.5
  [    5c]  $d.6
  [    61]  $d.7
  [    66]  $d.8
  [    6b]  init.c
  [    72]  $d.0
  [    77]  $d.1
  [    7c]  $d.2
  [    81]  $d.3
  [    86]  $d.4
  [    8b]  $d.5
  [    90]  $d.6
  [    95]  $d.7
  [    9a]  $d.8
  [    9f]  call_weak_fn
  [    ac]  $x.0
  [    b1]  $x.1
  [    b6]  $x.2
  [    bb]  $d.3
  [    c0]  $d.4
  [    c5]  $d.5
  [    ca]  $d.6
  [    cf]  $d.7
  [    d4]  $d.8
  [    d9]  crtbegin.c
  [    e4]  __do_init
  [    ee]  $x.0
  [    f3]  __do_init.__initialized
  [   10b]  __EH_FRAME_LIST__
  [   11d]  __do_init.__object
  [   130]  __do_fini
  [   13a]  __do_fini.__finalized
  [   150]  $d.1
  [   155]  $d.2
  [   15a]  __init
  [   161]  $d.3
  [   166]  __fini
  [   16d]  $d.4
  [   172]  $d.5
  [   177]  $d.6
  [   17c]  hell.c
  [   183]  $x.0
  [   188]  $d.1
  [   18d]  $d.2
  [   192]  $d.3
  [   197]  crtend.c
  [   1a0]  $d.0
  [   1a5]  $d.1
  [   1aa]  $x.0
  [   1af]  $x.1
  [   1b4]  $d.2
  [   1b9]  $d.3
  [   1be]  $d.4
  [   1c3]  $d.5
  [   1c8]  $d.6
  [   1cd]  $d.7
  [   1d2]  _start
  [   1d9]  main
  [   1de]  __libc_start_main

ld:

String dump of section '.strtab':
  [     1]  Scrt1.o
  [     9]  $x.0
  [     e]  $d.1
  [    13]  $d.2
  [    18]  $d.3
  [    1d]  $d.4
  [    22]  $d.5
  [    27]  $d.6
  [    2c]  $d.7
  [    31]  abi-note.c
  [    3c]  __abi_tag
  [    46]  $d.0
  [    4b]  $d.8
  [    50]  init.c
  [    57]  crti.o
  [    5e]  call_weak_fn
  [    6b]  $x.1
  [    70]  $x.2
  [    75]  crtn.o
  [    7c]  crtbegin.c
  [    87]  __do_init
  [    91]  __do_init.__initialized
  [    a9]  __EH_FRAME_LIST__
  [    bb]  __do_init.__object
  [    ce]  __do_fini
  [    d8]  __do_fini.__finalized
  [    ee]  __init
  [    f5]  __fini
  [    fc]  hell.c
  [   103]  crtend.c
  [   10c]  _DYNAMIC
  [   115]  __GNU_EH_FRAME_HDR
  [   128]  _GLOBAL_OFFSET_TABLE_
  [   13e]  $x
  [   141]  func1
  [   147]  __libc_start_main@GLIBC_2.34
  [   164]  __bss_start__
  [   172]  __cxa_finalize@GLIBC_2.17
  [   18c]  _edata
  [   193]  __bss_end__
  [   19f]  __data_start
  [   1ac]  __gmon_start__
  [   1bb]  __dso_handle
  [   1c8]  abort@GLIBC_2.17
  [   1d9]  _IO_stdin_used
  [   1e8]  __EH_FRAME_LIST_END__
  [   1fe]  func2
  [   204]  _end
  [   209]  __deregister_frame_info
  [   221]  __end__
  [   229]  __register_frame_info
  [   23f]  __bss_start
  [   24b]  main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants