Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 457630 - media-sound/mpg123 compiled by clang: segmentation fault
Summary: media-sound/mpg123 compiled by clang: segmentation fault
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal enhancement (vote)
Assignee: Thomas Orgis
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: systemwide-clang
  Show dependency tree
 
Reported: 2013-02-14 23:16 UTC by Vicente Olivert Riera (RETIRED)
Modified: 2013-07-22 06:53 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
mpg123-1.14.4 build log (file_457630.txt,54.59 KB, text/plain)
2013-04-01 11:26 UTC, Vicente Olivert Riera (RETIRED)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vicente Olivert Riera (RETIRED) gentoo-dev 2013-02-14 23:16:08 UTC
Compiles and install fine, but causes a segmentation fault when is used.

From gdb output, when running mplayer2:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff4b32a06 in ?? () from /usr/lib64/libmpg123.so.0

From mplayer2 output:

MPlayer interrupted by signal 11 in module: decode_audio
- MPlayer crashed by bad usage of CPU/FPU/RAM.
Comment 1 Thomas Orgis 2013-03-29 14:29:22 UTC
1. Any chance to get a backtrace indicating where in libmpg123 the crash occurs?
2. Does clang-built mpg123 work stand-alone?
3. Does disabling assembler code in mpg123 build help (--with-cpu=generic)?
Comment 2 Vicente Olivert Riera (RETIRED) gentoo-dev 2013-03-30 18:50:50 UTC
(In reply to comment #1)
> 1. Any chance to get a backtrace indicating where in libmpg123 the crash
> occurs?

#0  INT123_dct64_x86_64 () at dct64_x86_64.S:117
#1  0x00007ffff4b22c8a in INT123_synth_1to1_stereo_x86_64 (bandPtr_l=0x10789c0, bandPtr_r=0x10792c0, fr=0x1058ce0) at synth.c:430
#2  0x00007ffff4b2b111 in INT123_do_layer3 (fr=0x1058ce0) at layer3.c:2028
#3  0x00007ffff4b1fa83 in decode_the_frame (fr=0x1058ce0) at libmpg123.c:685
#4  0x00007ffff4b20208 in mpg123_decode_frame (mh=0x1058ce0, num=<optimized out>, audio=0x0, bytes=0x7fffffffbb48) at libmpg123.c:824
#5  0x0000000000531621 in ?? ()
#6  0x0000000000531b48 in ?? ()
#7  0x0000000000474d1e in ?? ()
#8  0x000000000042391a in ?? ()
#9  0x0000000000416edb in ?? ()
#10 0x00007ffff0b934bd in __libc_start_main () from /lib64/libc.so.6
#11 0x0000000000418fbd in ?? ()
#12 0x00007fffffffdea8 in ?? ()
#13 0x000000000000001c in ?? ()
#14 0x0000000000000002 in ?? ()
#15 0x00007fffffffe1dc in ?? ()
#16 0x00007fffffffe1ee in ?? ()
#17 0x0000000000000000 in ?? ()

> 2. Does clang-built mpg123 work stand-alone?

No. Segmentation fault again when I try to run "mpg123 music_file.mp3". Here is the backtrace:

#0  INT123_dct64_x86_64 () at dct64_x86_64.S:117
#1  0x00007ffff7bacc8a in INT123_synth_1to1_stereo_x86_64 (bandPtr_l=0x63db00, bandPtr_r=0x63e400, fr=0x630f10) at synth.c:430
#2  0x00007ffff7bb5111 in INT123_do_layer3 (fr=0x630f10) at layer3.c:2028
#3  0x00007ffff7ba9a83 in decode_the_frame (fr=0x630f10) at libmpg123.c:685
#4  0x00007ffff7baa208 in mpg123_decode_frame (mh=0x630f10, num=<optimized out>, audio=0x7fffffffdd18, bytes=0x7fffffffdd10) at libmpg123.c:824
#5  0x000000000040ad6b in play_frame () at mpg123.c:661
#6  0x000000000040bdbc in main (sys_argc=<optimized out>, sys_argv=<optimized out>) at mpg123.c:1140

> 3. Does disabling assembler code in mpg123 build help (--with-cpu=generic)?

Yes, with "--with-cpu=generic" works fine.
Comment 3 Thomas Orgis 2013-03-30 23:43:13 UTC
Ah, great. Well, me thinks we got an alignment issue in mpg123. Line 117 of dct64_x86_64.S ist the first of this block:

        movaps          (%rcx), %xmm0
        movaps          16(%rcx), %xmm1
        movaps          32(%rcx), %xmm2
        movaps          48(%rcx), %xmm3

Loaded in %rcx should be the address of costab_x86_64, which is defined in the same file:

        ALIGN32
ASM_NAME(costab_x86_64):

Now, ALIGN32 should expand to some expression that aligns the address to 32 bytes. Since mpg123 1.15.1 (which version are we talking about here, btw.?), this will be ".balign 32" if it is supported, otherwise ".align 5" or ".align 32", depending on configure heuristics. 

1. Can we ensure that this is the issue by making the crash go away (or occur elsewhere) when replacing all "movaps" by "movups" in dct64_x86_64.S? Simple 

  perl -pi -e 's:movaps:movups:'  src/libmpg123/dct64_x86_64.S

should do the trick.

2. Is the detection of assembler alignment bad? What does

  grep ASMALIGN src/config.h

show? Of course, configure output from mpg123 would also tell the story.

3. Just replacing ALIGN32 by ".balign 32" might do the trick, too (with movaps).


This alignment in assembly is such a basic feature that I dare not to suggest that this is broken with clang, rather that somehow mpg123 build detected the wrong syntax to use.
Comment 4 Vicente Olivert Riera (RETIRED) gentoo-dev 2013-04-01 11:26:33 UTC
Created attachment 343920 [details]
mpg123-1.14.4 build log

(In reply to comment #3)
> Since mpg123 1.15.1 (which version are we talking about here, btw.?)

We are talking about media-sound/mpg123-1.14.4, the current stable in portage tree.
Confirmed, media-sound/mpg123-1.15.1 doesn't have this problem.

> 1. Can we ensure that this is the issue by making the crash go away (or
> occur elsewhere) when replacing all "movaps" by "movups" in dct64_x86_64.S?
> Simple 
> 
>   perl -pi -e 's:movaps:movups:'  src/libmpg123/dct64_x86_64.S
> 
> should do the trick.

Done. The problem persists.

> 2. Is the detection of assembler alignment bad? What does
> 
>   grep ASMALIGN src/config.h
> 
> show? Of course, configure output from mpg123 would also tell the story.

$ grep ASMALIGN src/config.h
#define ASMALIGN_EXP 1

For the configure output, I have attached the full build log.

> 3. Just replacing ALIGN32 by ".balign 32" might do the trick, too (with
> movaps).

Done. The problem persists.
Comment 5 Thomas Orgis 2013-04-01 20:08:58 UTC
When you say the problem persists, you mean there is a crash, but I suppose it is not in dct64 anymore, but later (synth)? Otherwise I have a hard time explaining why 1.15.1 is fine. So, if updating the stable version is not an option, a fix should be to back-port the change to support balign (possibly just by hacking the ALIGN* macros in mangle.h to use .balign unconditionally as gcc and clang support that).
Comment 6 Vicente Olivert Riera (RETIRED) gentoo-dev 2013-04-04 16:57:15 UTC
(In reply to comment #5)
> When you say the problem persists, you mean there is a crash, but I suppose
> it is not in dct64 anymore, but later (synth)?

I mean there is a segfault again. But yes, you are right, it fails later (synth). Look at this:

$ gdb mpg123
...
Program received signal SIGSEGV, Segmentation fault.
INT123_synth_1to1_s_x86_64_asm () at synth_stereo_x86_64.S:89
89	synth_stereo_x86_64.S: No such file or directory.
(gdb) bt
#0  INT123_synth_1to1_s_x86_64_asm () at synth_stereo_x86_64.S:89
#1  0x00007ffff7baf04c in INT123_synth_1to1_stereo_x86_64 (bandPtr_l=<optimized out>, bandPtr_r=<optimized out>, fr=0x62ef00) at synth.c:434
#2  0x00007ffff7bb75f1 in INT123_do_layer3 (fr=0x62ef00) at layer3.c:2028
#3  0x00007ffff7bac453 in decode_the_frame (fr=0x62ef00) at libmpg123.c:685
#4  0x00007ffff7bac933 in mpg123_decode_frame (mh=0x62ef00, num=<optimized out>, audio=0x7fffffffdce8, bytes=0x7fffffffdce0) at libmpg123.c:824
#5  0x000000000040a623 in play_frame () at mpg123.c:661
#6  0x000000000040b4c3 in main (sys_argc=<optimized out>, sys_argv=<optimized out>) at mpg123.c:1140

> Otherwise I have a hard time explaining why 1.15.1 is fine. So, if updating 
> the stable version is not an option, a fix should be to back-port the change 
> to support balign (possibly just by hacking the ALIGN* macros in mangle.h to 
> use .balign unconditionally as gcc and clang support that).

I don't know. You are the maintainer of this package. If you wish you could file a stable request bug for 1.15.1.
Comment 7 Thomas Orgis 2013-04-05 08:14:09 UTC
Thanks for confirming. Since I am the upsteeam maintainer of mpg123 (not the gentoo package), you can be sure that I recommend using the stable versions I release as stable version in gentoo;-) Actually, there is 1.15.3 now, with bug fixes for people who insist on writing WAV to standard output.

But I guess it would be more appropriate if a gentoo dev does request/execute the version shift to fix this bug here. Those are still reading, right?
Comment 8 Vicente Olivert Riera (RETIRED) gentoo-dev 2013-04-05 10:11:04 UTC
(In reply to comment #7)
> But I guess it would be more appropriate if a gentoo dev does
> request/execute the version shift to fix this bug here. Those are still
> reading, right?

Yes, they are reading this bug too. We will wait for the maintaner's decission.
Thanks for your active cooperation, Thomas.