[all-commits] [llvm/llvm-project] 1981b1: [ELF] Demote symbols in /DISCARD/ discarded sectio...

Fangrui Song via All-commits all-commits at lists.llvm.org
Tue Oct 17 14:11:07 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1981b1b6b92f7579a30c9ed32dbdf3bc749c1b40
      https://github.com/llvm/llvm-project/commit/1981b1b6b92f7579a30c9ed32dbdf3bc749c1b40
  Author: Fangrui Song <i at maskray.me>
  Date:   2023-10-17 (Tue, 17 Oct 2023)

  Changed paths:
    M lld/ELF/LinkerScript.cpp
    M lld/ELF/LinkerScript.h
    M lld/ELF/MapFile.cpp
    M lld/ELF/Relocations.cpp
    M lld/ELF/Symbols.cpp
    M lld/ELF/Writer.cpp
    M lld/test/ELF/gc-sections-tls.s
    M lld/test/ELF/linkerscript/discard-section.s

  Log Message:
  -----------
  [ELF] Demote symbols in /DISCARD/ discarded sections to Undefined (#69295)

When an input section is matched by /DISCARD/ in a linker script, GNU ld
reports errors for relocations referencing symbols defined in the section:

    `.aaa' referenced in section `.bbb' of a.o: defined in discarded section `.aaa' of a.o

Implement the error by demoting eligible symbols to `Undefined` and changing
STB_WEAK to STB_GLOBAL. As a side benefit, in relocatable links, relocations
referencing symbols defined relative to /DISCARD/ discarded sections no longer
set symbol/type to zeros.

It's arguable whether a weak reference to a discarded symbol should lead to
errors. GNU ld reports an error and our demoting approach reports an error as
well.

Close #58891

Co-authored-by: Bevin Hansson <bevin.hansson at ericsson.com>




More information about the All-commits mailing list