[all-commits] [llvm/llvm-project] 1955a0: MC: Allocate initial fragment and define section s...

Fangrui Song via All-commits all-commits at lists.llvm.org
Thu Jul 24 23:38:09 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1955a01d63eceaf806faa29c2ed7c61e135889eb
      https://github.com/llvm/llvm-project/commit/1955a01d63eceaf806faa29c2ed7c61e135889eb
  Author: Fangrui Song <i at maskray.me>
  Date:   2025-07-24 (Thu, 24 Jul 2025)

  Changed paths:
    M llvm/include/llvm/MC/MCContext.h
    M llvm/include/llvm/MC/MCSection.h
    M llvm/include/llvm/MC/MCXCOFFStreamer.h
    M llvm/lib/MC/ELFObjectWriter.cpp
    M llvm/lib/MC/MCAssembler.cpp
    M llvm/lib/MC/MCContext.cpp
    M llvm/lib/MC/MCELFStreamer.cpp
    M llvm/lib/MC/MCMachOStreamer.cpp
    M llvm/lib/MC/MCObjectStreamer.cpp
    M llvm/lib/MC/MCSection.cpp
    M llvm/lib/MC/MCStreamer.cpp
    M llvm/lib/MC/MCXCOFFStreamer.cpp
    M llvm/test/CodeGen/XCore/section-name.ll
    M llvm/test/MC/ELF/section-sym2.s
    R llvm/test/MC/ELF/undefined-debug.s

  Log Message:
  -----------
  MC: Allocate initial fragment and define section symbol in changeSection

13a79bbfe583e1d8cc85d241b580907260065eb8 (2017) introduced fragment
creation in MCContext for createELFSectionImpl, which was inappropriate.
Fragments should only be created when using MCSteramer, not during
`MCContext::get*Section` calls.
`initMachOMCObjectFileInfo` defines multiple sections, some of which may
not be used by the code generator. This caused symbol names matching
these sections to be incorrectly marked as undefined (see
https://reviews.llvm.org/D55173).

The fragment code was later replicated in other file formats, such as
WebAssembly (see https://reviews.llvm.org/D46561), XCOFF, and GOFF.

This patch fixes the problem by moving initial fragment allocation from
MCContext::createSection to MCStreamer::changeSection.
While MCContext still creates a section symbol, the symbol is not
attached to the initial fragment.
In addition, move `emitLabel`/`setFragment` from `switchSection*` and
overridden changeSection to `MCObjectStreamer::changeSection` for
consistency.

* test/CodeGen/XCore/section-name.ll now passes. XCore doesn't support
  MCObjectStreamer. I don't think the MCAsmStreamer output behavior
  change matters.

Pull Request: https://github.com/llvm/llvm-project/pull/150574



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list