#1107858 libc++-19-dev: Can't link libc++.a to large binaries like chromium on loong64

Package:
libc++-19-dev
Source:
libc++-19-dev
Description:
LLVM C++ Standard library (development files)
Submitter:
Jianfeng Liu
Date:
2025-06-16 02:15:02 UTC
Severity:
normal
Tags:
#1107858#5
Date:
2025-06-16 02:13:43 UTC
From:
To:
Chromium is linking libc++ staticly since 137.0.7151.103-1. While on
LoongArch64 platform
the default code model normal provides 256MiB PC-relative addressing
space[1], which is not
enough for chromium. I will get following errors like:

ld.lld-19: error:
/lib/loongarch64-linux-gnu/libc++.a(cxa_demangle.cpp.o):(function
(anonymous
namespace)::itanium_demangle::AbstractManglingParser<(anonymous
namespace)::itanium_demangle::ManglingParser<(anonymous
namespace)::DefaultAllocator>, (anonymous
namespace)::DefaultAllocator>::parseEncoding(bool):
.text._ZN12_GLOBAL__N_116itanium_demangle22AbstractManglingParserINS0_14ManglingParserINS_16DefaultAllocatorEEES3_E13parseEncodingEb+0x910):
relocation R_LARCH_B26 out of range: 239992688 is not in [-134217728,
134217727]; references 'memmove'

After recompiling llvm with code model medium, chromium can get linked
fine.

Here is my patch setting medium code model:

diff --git a/debian/rules b/debian/rules
index b3909dc2..6b7f1a77 100755
--- a/debian/rules
+++ b/debian/rules
@@ -155,6 +155,11 @@ CFLAGS_EXTRA = -Wno-unused-command-line-argument
CXXFLAGS_EXTRA = -Wno-unused-command-line-argument
LDFLAGS_EXTRA = -Wl,--build-id

+ifeq (loong64,$(DEB_HOST_ARCH))
+ CFLAGS_EXTRA += -mcmodel=medium
+ CXXFLAGS_EXTRA += -mcmodel=medium
+endif
+
# collect all flags for stage 1 toolchain build only
STAGE_1_CFLAGS = $(CFLAGS) $(CFLAGS_EXTRA) $(CPPFLAGS)
STAGE_1_CXXFLAGS = $(CXXFLAGS) $(CXXFLAGS_EXTRA) $(CPPFLAGS)
@@ -1031,8 +1036,8 @@ endif
touch $@

# Remove some new flags introduced by dpkg 1.22.0;
-STAGE_2_WASM_CFLAGS := $(filter-out -march=% -mfpu=% -fcf-protection% 
-mbranch-protection%, $(STAGE_2_CFLAGS))
-STAGE_2_WASM_CXXFLAGS := $(filter-out -march=% -mfpu=% -fcf-protection% 
-mbranch-protection%, $(STAGE_2_CXXFLAGS))
+STAGE_2_WASM_CFLAGS := $(filter-out -march=% -mfpu=% -fcf-protection%
-mbranch-protection% -mcmodel=%, $(STAGE_2_CFLAGS))
+STAGE_2_WASM_CXXFLAGS := $(filter-out -march=% -mfpu=% -fcf-protection%
-mbranch-protection% -mcmodel=%, $(STAGE_2_CXXFLAGS))

build-wasm/compiler-rt-%: cpu = $(@:build-wasm/compiler-rt-%=%)
build-wasm/compiler-rt-%:

[1]
https://github.com/loongson/la-abi-specs/blob/release/laelf.adoc#code_models