Skip to content

[Deepin-Kernel-SIG] [linux 6.6.y] kbuild: deb-pkg: strip orphaned debug labels from LoongArch modules - #2258

Merged
opsiff merged 1 commit into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-11-10-loongarch
Nov 10, 2026
Merged

opsiff merged 1 commit into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-11-10-loongarch

Conversation

@opsiff

@opsiff opsiff commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

With CONFIG_DEBUG_INFO, gcc emits .L-prefixed labels for function and block boundaries and for location views (.LVL, .LBI, .LBB, .LFB, .LPFE), and the assembler keeps them in .symtab as long as a debug section references them. On x86-64 those references are expressed as a section symbol plus an addend and the labels are discarded, but the LoongArch assembler has to name them in relocations:

0000000000000057 R_LARCH_64          .LFB1 + 0
0000000000000015 R_LARCH_ADD_ULEB128 .LVL0 + 0

so they end up in the object's symbol table.

INSTALL_MOD_STRIP=1 expands to "strip --strip-debug", which is a section operation: it drops .debug_* and .rela.debug_* but leaves the symbol table alone, so every label that was only referenced from debug data stays behind as an orphan. On 7.2.2-loong64-desktop-rolling 86.7% of the roughly 3M module symbols are such labels. Nothing uses them at run time, yet they cost 22% of the module payload (168 MB -> 130 MB) and 19% of the linux-image package (195 MB -> 157 MB). This is the same problem commit ac031f2 ("kbuild: add option for stripping modules while installing them") addressed for the general debug-info case.

Strip them with --discard-locals as well. binutils removes a local symbol only when its name still follows the assembler's local label convention (.L, .., .L and the L pseudo labels) and no relocation in the output still names it: mark_symbols_used_in_relocations() sets BSF_KEEP on every relocation target and filter_symbols() keeps those unconditionally. What the module loader needs therefore survives -- the relocation set of every module is byte-for-byte identical before and after, .LC, .LPFE and the -fpatchable-function-entry labels stay, exactly one SHT_SYMTAB remains as elf_validity_cache_index_sym() requires, and the modules are still signed, because modules_install strips before it signs. The dbg package is built from the unstripped modules in the build tree, so it keeps all debug information.

Restrict this to LoongArch on a GNU toolchain, everyone else keeps INSTALL_MOD_STRIP=1. Other architectures never see these labels: on x86-64 the option drops two unreferenced .LC symbols out of an amdgpu.ko and leaves all 429,648 relocations alone, so there is nothing to gain there. LLVM builds have to keep the plain option, because kbuild hands the same value to llvm-strip for LLVM=1 and llvm-strip refuses to strip a symbol that a relocation still names, aborting the build, while clang does emit such labels for string constants:

llvm-strip: error: 'super.ko': not stripping symbol '.L.str.1'
because it is named in a relocation

Clang none the less generates none of the debug labels that make the package grow, so an LLVM build loses nothing by being left alone.

Boot tested with qemu-system-loongarch64 (EDK2 firmware, vmlinuz.efi, test modules loaded from the initramfs with finit_module()): modules stripped with --strip-debug, --discard-locals and --strip-unneeded all load with rc=0, while --strip-all is rejected with "module has no symbols (stripped?)".

Summary by Sourcery

Reduce stripped LoongArch module and kernel package sizes by discarding unused debug labels while preserving required symbols, relocations, and module functionality.

Bug Fixes:

  • Remove orphaned debug-only local symbols from stripped LoongArch kernel modules to reduce package size without affecting module loading or signing.

Build:

  • Apply the additional local-symbol stripping only to GNU-toolchain LoongArch builds while preserving existing stripping behavior for other architectures and LLVM builds.

With CONFIG_DEBUG_INFO, gcc emits .L-prefixed labels for function and
block boundaries and for location views (.LVL, .LBI, .LBB, .LFB, .LPFE),
and the assembler keeps them in .symtab as long as a debug section
references them.  On x86-64 those references are expressed as a section
symbol plus an addend and the labels are discarded, but the LoongArch
assembler has to name them in relocations:

    0000000000000057 R_LARCH_64          .LFB1 + 0
    0000000000000015 R_LARCH_ADD_ULEB128 .LVL0 + 0

so they end up in the object's symbol table.

INSTALL_MOD_STRIP=1 expands to "strip --strip-debug", which is a section
operation: it drops .debug_* and .rela.debug_* but leaves the symbol
table alone, so every label that was only referenced from debug data
stays behind as an orphan.  On 7.2.2-loong64-desktop-rolling 86.7% of the
roughly 3M module symbols are such labels.  Nothing uses them at run time,
yet they cost 22% of the module payload (168 MB -> 130 MB) and 19% of the
linux-image package (195 MB -> 157 MB).  This is the same problem
commit ac031f2 ("kbuild: add option for stripping modules while
installing them") addressed for the general debug-info case.

Strip them with --discard-locals as well.  binutils removes a local
symbol only when its name still follows the assembler's local label
convention (.L, .., _.L_ and the L<digits> pseudo labels) *and* no
relocation in the output still names it: mark_symbols_used_in_relocations()
sets BSF_KEEP on every relocation target and filter_symbols() keeps those
unconditionally.  What the module loader needs therefore survives -- the
relocation set of every module is byte-for-byte identical before and
after, .LC, .LPFE and the -fpatchable-function-entry labels stay, exactly
one SHT_SYMTAB remains as elf_validity_cache_index_sym() requires, and
the modules are still signed, because modules_install strips before it
signs.  The dbg package is built from the unstripped modules in the build
tree, so it keeps all debug information.

Restrict this to LoongArch on a GNU toolchain, everyone else keeps
INSTALL_MOD_STRIP=1.  Other architectures never see these labels: on
x86-64 the option drops two unreferenced .LC symbols out of an amdgpu.ko
and leaves all 429,648 relocations alone, so there is nothing to gain
there.  LLVM builds have to keep the plain option, because
kbuild hands the same value to llvm-strip for LLVM=1 and llvm-strip
refuses to strip a symbol that a relocation still names, aborting the
build, while clang does emit such labels for string constants:

    llvm-strip: error: 'super.ko': not stripping symbol '.L.str.1'
    because it is named in a relocation

Clang none the less generates none of the debug labels that make the
package grow, so an LLVM build loses nothing by being left alone.

Boot tested with qemu-system-loongarch64 (EDK2 firmware, vmlinuz.efi,
test modules loaded from the initramfs with finit_module()): modules
stripped with --strip-debug, --discard-locals and --strip-unneeded all
load with rc=0, while --strip-all is rejected with "module has no symbols
(stripped?)".

Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
@sourcery-ai

sourcery-ai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Configuration

Adjust module stripping for GNU-toolchain LoongArch builds to discard orphaned local debug labels while preserving the existing behavior elsewhere.

  • scripts/package/builddeb L36-43

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from opsiff. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the LoongArch module-stripping change.

No open issues 🎉

What changed in this PR

Reduces LoongArch kernel module sizes in Debian packages by removing orphaned local debug labels during module installation.

Changes:

  • Uses --strip-debug --discard-locals for LoongArch builds when the selected strip tool identifies itself as GNU strip.
  • Preserves INSTALL_MOD_STRIP=1 for other architectures and non-GNU strip tools, including LLVM.
File Description
scripts/​package/​builddeb Selects module stripping options based on architecture and strip tool.

Review effort: Balanced

@opsiff
opsiff merged commit bdf0daa into deepin-community:linux-6.6.y Nov 10, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants