[Home]

Summary:ASTERISK-21967: CFLAG Improvement to prevent compiler error in Virtual Machine environments
Reporter:PowerPBX (PowerPBX)Labels:
Date Opened:2013-06-27 13:05:57Date Closed:2018-01-02 08:30:32.000-0600
Priority:MajorRegression?
Status:Closed/CompleteComponents:Core/General
Versions:1.8.22.0 11.4.0 Frequency of
Occurrence
Related
Issues:
is related toASTERISK-20128 Virtualized asterisk.org 1.8.14.0 no longer runs in a KVM virtualized environment. Compiles without error, but fails with Illegal instruction on launch Regression since 1.8.13.0 Last good 1.8.12.2
Environment:CentOS 6 KVM Virtual Machine, Intel or AMDAttachments:( 0) Makefile.rules.patch
Description:At some point not too long ago a default CFLAG setting for i386 and x86_64 optimization must have been changed.  It appears to now be too aggressive in some situations for some virtualization environments.  Asterisk compiles without error but fails to run.

The error that is typically observed is:

{noformat}
/usr/sbin/safe_asterisk: line 147: 32428 Illegal instruction(core dumped) nice -n $PRIORITY ${ASTSBINDIR}/asterisk -f ${CLIARGS} ${ASTARGS} > /dev/${TTY} 2>&1 < /dev/${TTY}
Asterisk ended with exit status 132
Asterisk exited on signal 4.
cat: /var/run/asterisk/asterisk.pid: No such file or directory
Automatically restarting Asterisk.
{noformat}

See this issue for more explanation.
ASTERISK-20128

I have identified what I believe to be a solution to this problem.
In Asterisk 11.4.0, Makfile.rules, line 87-88

ifeq ($(findstring BUILD_NATIVE,$(MENUSELECT_CFLAGS)),BUILD_NATIVE)
   _ASTCFLAGS+=-march=native

I believe this should be changed to:

ifeq ($(findstring BUILD_NATIVE,$(MENUSELECT_CFLAGS)),BUILD_NATIVE)
   _ASTCFLAGS+=-mtune=native

This appears to correct the problem in my limited testing. This flag is available since gcc v4.2 according to the gcc documentation at the link below.  Prior to that version the setting should probably be -mtune=generic.   For even more universal compatibility perhaps the default should just be -mtune=generic.   That also corrected my problems and is even less likely to be a problem if I were to move my VPS to different hardware although is likely less optimal for newer CPU's.  Perhaps an additional check box could be added to menuselect for more aggressive compiling using -march=native.

http://gcc.gnu.org/onlinedocs/gcc-4.2.4/gcc/i386-and-x86_002d64-Options.html#i386-and-x86_002d64-Options
Comments:By: Matt Jordan (mjordan) 2013-07-01 12:40:51.963-0500

We could certainly give that a try, although it may be worthwhile to put some versioning checks of {{gcc}} in there as well.

Do you mind writing a patch for Makefile and attaching it to this issue in unified diff format after signing a license contributor agreement?

Thanks!


By: Matt Jordan (mjordan) 2013-07-01 12:41:19.280-0500

As an FYI: given the amount of heartburn this issue has caused, I'd be more than willing to have this go into 1.8+.

By: Trent Creekmore (tcreek) 2013-07-09 00:00:52.665-0500

I tried it and still get:


"Asterisk ended with exit status 127
Asterisk died with code 127."



By: PowerPBX (PowerPBX) 2013-07-11 10:43:56.171-0500

You didn't explain your environment or if it worked before.  You also did not mention if you tried -mtune=generic which is the next step if -mtune=native fails.  That is not even the proper error so you probably have some other problem.

The typical error which I have now added to the original explanation is:

{noformat}
/usr/sbin/safe_asterisk: line 147: 32428 Illegal instruction(core dumped) nice -n $PRIORITY ${ASTSBINDIR}/asterisk -f ${CLIARGS} ${ASTARGS} > /dev/${TTY} 2>&1 < /dev/${TTY}
Asterisk ended with exit status 132
Asterisk exited on signal 4.
cat: /var/run/asterisk/asterisk.pid: No such file or directory
Automatically restarting Asterisk.
{noformat}

By: Rusty Newton (rnewton) 2013-07-26 17:36:03.583-0500

@PowerPBX - we need you to [sign the license agreement|https://issues.asterisk.org/jira/secure/DigiumLicense.jspa] and then attach the patch to the issue (in a unified diff format).

By: PowerPBX (PowerPBX) 2013-08-14 13:49:57.050-0500

I would like to help but I am not a coder.  I could probably come up with something but it may not be very elegant or not the proper solution.  I don't know when I will be able to find time to do this.

For now I have been compiling Asterisk with -mtune=native and it seems to be working for me.

By: Miguel Molina (coolmig) 2015-10-05 01:37:30.722-0500

Patch proposed by PowerPBX. Created in Asterisk 13.5.0.

By: Miguel Molina (coolmig) 2015-10-05 01:38:56.107-0500

The patch works just fine. I'm running Asterisk 13.5.0 in a VM inside a RHEL virtualization host.

By: Corey Farrell (coreyfarrell) 2017-12-15 10:42:11.675-0600

Miguel,

Would you like to pursue this further?  If so please submit your patch to gerrit for code review.

----

Thanks for the contribution! If you'd like your contribution to be included faster, you should submit your patch for code review by the Asterisk Developer Community. To do so, please follow the Code Review \[1\] instructions on the wiki. Be sure to:
* Verify that your patch conforms to the Coding Guidelines \[2\]
* Review the Code Review Checklist \[3\] for common items reviewers will look for
* If necessary, provide tests for the Asterisk Test Suite that verify the correctness of your patch \[4\]

When ready, submit your patch and any tests to Gerrit \[5\] for code review.

Thanks!

\[1\] https://wiki.asterisk.org/wiki/display/AST/Code+Review
\[2\] https://wiki.asterisk.org/wiki/display/AST/Coding+Guidelines
\[3\] https://wiki.asterisk.org/wiki/display/AST/Code+Review+Checklist
\[4\] https://wiki.asterisk.org/wiki/display/AST/Asterisk+Test+Suite+Documentation
\[5\] https://wiki.asterisk.org/wiki/display/AST/Gerrit+Usage

By: Asterisk Team (asteriskteam) 2018-01-02 08:30:32.475-0600

Suspended due to lack of activity. This issue will be automatically re-opened if the reporter posts a comment. If you are not the reporter and would like this re-opened please create a new issue instead. If the new issue is related to this one a link will be created during the triage process. Further information on issue tracker usage can be found in the Asterisk Issue Guidlines [1].
[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+Issue+Guidelines