Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perlcc does not return an error exit code when dependency modules are missing #445

Closed
agentzh opened this issue Oct 30, 2022 · 2 comments
Closed

Comments

@agentzh
Copy link
Contributor

agentzh commented Oct 30, 2022

When some Perl dependency modules are missing, perlcc does not return an error exit code but a zero code. Worse, it still generates a faulty binary executable that is seldom behaving. I'm using the latest github master branch of this repo (commit 862bdf2). And I'm using Fedora x86_64 Linux with a multi-threaded build of perl 5.24.4. A single-threaded build of perl 5.24.4 also exhibits this problem.

Here's a minimal reproducer:

use Blah;

print "ok";
$ /opt/perl524-thr/bin/perlcc -O2 -S -o b.out b.pl
/opt/perl524-thr/bin/perlcc: Unexpected compiler output
Can't locate Blah.pm in @INC (you may need to install the Blah module) (@INC contains: /opt/perl524-thr/lib/site_perl/5.24.4/x86_64-linux-thread-multi /opt/perl524-thr/lib/site_perl/5.24.4 /opt/perl524-thr/lib/5.24.4/x86_64-linux-thread-multi /opt/perl524-thr/lib/5.24.4 .) at b.pl line 1.
 BEGIN failed--compilation aborted at b.pl line 1.

$ echo $?
0

$ ./b.out

And the following patch fixes this:

diff --git a/script/perlcc.PL b/script/perlcc.PL
index b62371f5..13269bed 100644
--- a/script/perlcc.PL
+++ b/script/perlcc.PL
@@ -465,6 +465,9 @@ sub compile_byte {
     } else {
 	my @error = grep { !/^$Input syntax OK$/o } @$error_r;
 	@error = grep { !/^No package specified for compilation, assuming main::$/o } @error;
+	if (grep { /Can't locate \S+ in \@INC \(/ } @error) {
+	    die "$0: Missing Perl modules\n@error";
+	}
 	warn "$0: Unexpected compiler output\n@error" if @error and opt('v')<5;
 	warn "@error" if @error and opt('v')>4;
     }
@@ -590,6 +593,9 @@ sub compile_cstyle {
         if (opt('check')) {
             print "@error" if @error;
         } else {
+	    if (grep { /Can't locate \S+ in \@INC \(/ } @error) {
+		die "$0: Missing Perl modules\n@error";
+	    }
             warn "$0: Unexpected compiler output\n@error" if @error and opt('v')<5;
             warn "@error" if @error and opt('v')>4;
         }

Does it look good enough?

@rurban
Copy link
Owner

rurban commented Nov 1, 2022

Yes, please PR

@rurban
Copy link
Owner

rurban commented Nov 1, 2022

merged

@rurban rurban closed this as completed Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants