openwrt / openwrt/packages

Perl index() function broken on some MUSL systems

Open
#20,162 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Makefile
Stars
4.6k
Forks
4k
Avg merge
3d 12h
Merged PRs (30d)
134

Description

Describe the bug

A bug in perl and/or musl (there is some disagreement where the actual bug is) requires that -D_GNU_SOURCE be used for building perl for use with musl. Otherwise perl's index() string function fails. There are likely other perl functions that fail, since the underlying cause of the problem is that libc's memmem() function is not available to perl.

OpenWrt version

22.03.2, snapshot, but likely all

OpenWrt target/subtarget

mediatek/mt7622

Device

BPI-R64

Image kind

Official downloaded image

Steps to reproduce
#!/usr/bin/perl

my $string1 = "abcabc";
my $string2 = $string1;
my $affected = index($string1, $string2) != 0 ? "AFFECTED - you need to fix perl!" : "NOT affected - your perl is fine!";

printf "index=%d - your system is %s\n", index($string1, $string2), $affected;

Run the above perl program.

Actual behaviour

On affected systrems (notably aarch64/musl) index will be a large negative number, often -549755813888

Expected behaviour

In the sample program the index of a string in an identical string should always be zero.

Additional info

This bug is fixed in any recent version of perl. It can be fixed in OpenWrt by simply adding -D_GNU_SOURCE explicitly to the cflags through perl's Configure script.

Diffconfig

No response

Terms
  • I am reporting an issue for OpenWrt, not an unsupported fork.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Perl package build configuration and Perl's Configure script, then reproduce the issue with the sample program on an affected musl system. Check that the build passes -D_GNU_SOURCE explicitly and verify that the program reports index=0 instead of a large negative value.

Written by the indexing model from the issue text.

Assessment

Tech stack
perl
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.