Bug 132294 - [PATCH] lang/ruby18: Add option to build with Profile-Guided Optimization
Summary: [PATCH] lang/ruby18: Add option to build with Profile-Guided Optimization
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-ruby (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-04 00:10 UTC by Mario Sergio Fujikawa Ferreira
Modified: 2012-02-10 02:01 UTC (History)
1 user (show)

See Also:


Attachments
file.diff (3.06 KB, patch)
2009-03-04 00:10 UTC, Mario Sergio Fujikawa Ferreira
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mario Sergio Fujikawa Ferreira freebsd_committer freebsd_triage 2009-03-04 00:10:02 UTC
- Add WITH_PGO to build with Profile-Guided Optimization

Port maintainer (stas@FreeBSD.org) is cc'd.

Generated with FreeBSD Port Tools 0.77

Fix: --- ruby+pgo-1.8.7.72_1,1.patch begins here ---
Comment 1 Edwin Groothuis freebsd_committer freebsd_triage 2009-03-04 00:10:47 UTC
Responsible Changed
From-To: freebsd-ports-bugs->stas

Over to maintainer (via the GNATS Auto Assign Tool)
Comment 2 Mario Sergio Fujikawa Ferreira freebsd_committer freebsd_triage 2009-06-14 11:56:49 UTC
- Updated diff against latest port version 1.8.7.160_1,1.
- No changes. It is just an updated diff.
- You can remove the "${.TARGET}" lines after testing. They are
  meant for debugging only.

--- patch-ruby18-v1.8.7.160_1,1-Makefile begins here ---
--- Makefile.orig	2009-06-14 00:00:32.000000000 -0300
+++ Makefile	2009-06-14 07:46:21.000000000 -0300
@@ -37,6 +37,7 @@
 OPTIONS=	PTHREADS "Enable pthreads support (may break some apps)" off \
 		ONIGURUMA "Build with oniguruma regular expressions lib" off \
 		IPV6 "Enable IPv6 support" on \
+		PGO "Enable Profile-Guided Optimization" off \
 		RDOC "Build and install Rdoc indexes" off \
 		DEBUG "Compile-in debug info" off
 
@@ -56,6 +57,10 @@
 CFLAGS+=	${PTHREAD_CFLAGS}	# Keep this, else ruby will fail to load
 LDFLAGS+=	${PTHREAD_LIBS}		# libraries dependent op libpthread.
 
+.if defined(WITH_PGO)
+PKGNAMESUFFIX:=	${PKGNAMESUFFIX}+pgo
+.endif
+
 .if defined(WITH_PTHREADS)
 CONFIGURE_ARGS+=--enable-pthread
 PKGNAMESUFFIX:=	${PKGNAMESUFFIX}+pthreads
@@ -91,8 +96,14 @@
 CONFIGURE_ARGS+=	--enable-ipv6
 .endif
 
+.if defined(WITH_PGO)
+CONFIGURE_ENV=	CFLAGS="${CFLAGS} -fprofile-generate" \
+		LDFLAGS="-fprofile-generate" \
+		LIBS="${LDFLAGS}"
+.else
 CONFIGURE_ENV=	CFLAGS="${CFLAGS}" \
 		LIBS="${LDFLAGS}"
+.endif
 
 .if ${RUBY_VER} == ${RUBY_DEFAULT_VER}
 MLINKS=		${RUBY_NAME}.1 ruby.1
@@ -163,6 +174,13 @@
 	cd ${WRKSRC}/ && ${PATCH} -p0 < ${PATCHDIR}/extrapatch-oniguruma-reggnu.c
 .endif
 
+.if defined(WITH_PGO)
+.if target(pre-build)
+.error Makefile error since pre-build target has already been defined
+.endif
+pre-build: pgo
+.endif
+
 post-build:
 #
 # Hack to allow modules to be installed into separate PREFIX and/or under user
@@ -314,4 +332,46 @@
 	(cd ${WRKSRC}/rubyspec && git clone git://github.com/rubyspec/mspec.git)
 	(cd ${WRKSRC}/rubyspec/rubyspec && env PATH=${WRKSRC}/rubyspec/mspec/bin:${PATH} mspec -t ${PREFIX}/bin/ruby${RUBY_SUFFIX})
 
+.if defined(WITH_PGO)
+pgo: pgo-pre-build pgo-build pgo-run pgo-post-run pgo-clean
+	@${ECHO_MSG} "===> ${.TARGET} <==="
+
+pgo-pre-build:
+	@${ECHO_MSG} "===> ${.TARGET} <==="
+	@${FIND} ${BUILD_WRKSRC} -type f -name Makefile -exec \
+		${REINPLACE_CMD} -E \
+			-e 's,^(((C|LD)FLAGS|LDSHARED|ldflags)[[:space:]]*=.*)-fprofile-generate,\1,' \
+			-e 's,^(CFLAGS[[:space:]]*=.*)-fprofile-use,\1,' \
+			-e 's,^(((C|LD)FLAGS|LDSHARED|ldflags)[[:space:]]*=.*)$$,\1 -fprofile-generate,' \
+			{} \;
+
+pgo-build:
+	@${ECHO_MSG} "===> ${.TARGET} <==="
+	@(cd ${BUILD_WRKSRC}; ${SETENV} ${MAKE_ENV} ${MAKE} ${MAKE_FLAGS} ${MAKEFILE} ${MAKE_ARGS} ${ALL_TARGET})
+
+pgo-run: test
+# Check everything to generate profiling information.
+# We will ignore any errors if test target works
+	@-(cd ${BUILD_WRKSRC}; ${MAKE} check)
+
+pgo-post-run:
+	@${ECHO_MSG} "===> ${.TARGET} <==="
+	@${FIND} ${BUILD_WRKSRC} -type f -name Makefile -exec \
+		${REINPLACE_CMD} -E \
+			-e 's,^(((C|LD)FLAGS|LDSHARED|ldflags)[[:space:]]*=.*)-fprofile-generate,\1,' \
+			-e 's,^(CFLAGS[[:space:]]*=.*)-fprofile-use,\1,' \
+			-e 's,^(CFLAGS[[:space:]]*=.*)$$,\1 -fprofile-use,' \
+			{} \;
+	@${REINPLACE_CMD} -E \
+		-e 's,-fprofile-generate,-fprofile-use,g' \
+		${CONFIGURE_WRKSRC}/config.status
+
+pgo-clean:
+	@${ECHO_MSG} "===> ${.TARGET} <==="
+	@(cd ${BUILD_WRKSRC}; ${MAKE} clean)
+.endif # if defined(WITH_PGO)
+
+build-env:
+	@${ECHO_CMD} "===> ${.TARGET} <===" "[${CONFIGURE_ENV}]"
+
 .include <bsd.port.post.mk>
--- patch-ruby18-v1.8.7.160_1,1-Makefile ends here ---

-- 
Mario S F Ferreira - DF - Brazil - "I guess this is a signature."
feature, n: a documented bug | bug, n: an undocumented feature
Comment 3 Stanislav Sedov freebsd_committer freebsd_triage 2009-06-14 12:51:42 UTC
Hi, Mario!

What's regarding the amd64 problem I asked before? Is it fixed?
If you missed the prvious email, I'm including it here.

Begin forwarded message:

Date: Tue, 7 Apr 2009 12:41:14 +0400
From: Stanislav Sedov <stas@FreeBSD.org>
To: Mario Sergio Fujikawa Ferreira <lioux@FreeBSD.org>
Subject: Re: Testers for lang/ruby18 with Profile-Guided Optimization


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sat, 28 Feb 2009 09:19:26 -0300
Mario Sergio Fujikawa Ferreira <lioux@FreeBSD.org> mentioned:

> Hi,
> 
> 	I did some work on the lang/ruby18 to enable Profile-Guided
> Optimization (PGO) build support.
> 
> 	What I did? (Steps 1-4 handled by pgo port target).
> 
> ------- RECIPE
> 	1) Compile everything with CFLAGS/LDFLAGS containing
> 	  '-fprofile-generate';
> 
> 	2) Run lots of test cases to generate profiling information
> 	   (make check);
> 
> 	3) Remove all binaries leaving only the profiling information behind;
> 
> 	4) Replace all instances of '-fprofile-generate' with
> 	   '-fprofile-use';
> 
> 	5) Re-compile everything using the profiling information.
> -------
> 
> 	If I did it correctly, you should not notice any differences
> on port usage aside from PGO option and a huge build compilation
> time. Please, verify if you can that I did all steps of the "RECIPE"
> correctly.
> 
> 	I am not a ruby expert so I would like input on this one:
> 
> 	1) Does it perform better than ruby18 compiled without PGO?
> 	   Hard number benchmarks welcome. Check
> 	   http://github.com/acangiano/ruby-benchmark-suite/tree/master
> 
> 	2) Also, could others run specification conformance
> 	   verification checks on the resulting ruby interpreter?
> 	   So that we have multiple cross verification. Perhaps,
> 	   with rubyspec?
> 
> 	I hope you find this useful and that it performs as expected.
> I want to go after lang/ruby19. Perhaps, even python and perl5.
> 
> 	The modified port file can be found at
> 
> http://people.freebsd.org/~lioux/ruby18-pgo-2009022800.tbz
> 
> but the patch is so small that I have it as an attachment.
> 
> 	Regards,
> 
> -- 
> Mario S F Ferreira - DF - Brazil - "I guess this is a signature."
> feature, n: a documented bug | bug, n: an undocumented feature
> 
> 
> !DSPAM:49a92be2967008612027430!
> 

Hi!

Thanks for a great work. I'll look which benchmark suite I can intergrate
into the port to profile ruby more precisely.

BTW, is it supposed to work on amd64? I'm receiving the following:
cc -shared -fprofile-generate -Wl,-soname,libruby18.so.18  array.o  bignum.o  class.o  compar.o  dir.o  dln.o  enum.o  enumerator.o  error.o  eval.o  file.o  gc.o  hash.o  inits.o  io.o  marshal.o  math.o  numeric.o  object.o  pack.o  parse.o  process.o  prec.o  random.o  range.o  re.o  regex.o  ruby.o  signal.o  sprintf.o  st.o  string.o  struct.o  time.o  util.o  variable.o  version.o   dmyext.o -lcrypt -lm  -rpath=/usr/lib:/usr/local/lib -pthread  -o libruby18.so.18
/usr/bin/ld: /usr/lib/libgcov.a(_gcov_one_value_profiler.o): relocation R_X86_64_32 can not be used when making a shared object; recompile with -fPIC
/usr/lib/libgcov.a: could not read symbols: Bad value
*** Error code 1

Guess we need a PIC version of gcov...

- -- 
Stanislav Sedov
ST4096-RIPE
-----BEGIN PGP SIGNATURE-----

iEYEARECAAYFAknbEa4ACgkQK/VZk+smlYFL+wCeKNM6sCjKnvrmlJ/xvIui5bI1
jH4Anizk6Apf3DZHIdbi5YXpiX5HRuT3
=L3b3
-----END PGP SIGNATURE-----

Best regards,
-- 
Stanislav Sedov
ST4096-RIPE
Comment 4 Mario Sergio Fujikawa Ferreira freebsd_committer freebsd_triage 2009-06-23 17:24:23 UTC
Hi,

  I do not think this is exclusive to PGO (profile guided optimization) builds. I am receiving the exact same error message on math/libjbigi (which is now marked broken because of this). It is not just recompiling with -fPIC. That did not fix math/libjbigi.

/usr/bin/ld: /usr/lib/libgcov.a(_gcov_one_value_profiler.o): relocation R_X86_64_32 can not be used when making a shared object; recompile with -fPIC

  Unfortunately, I do not have an amd64 FBSD install to pursue this one. I am not even sure how to begin. We might need someone knowledgeable on the gcc build toolchain.

  My suggestion would be (perhaps) checking math/libjibi 1st. It could be an easier target (very small build). We could fix that one 1st then try the same fix on lang/ruby18.

  However, I would require your assistance since I do not have a amd64 FBSD install.

  Incidentally, this is the exact same error message reported for the www/firefox3 PGO PR ports/132231. I am CCing the firefox3 maintainer so that he can follow this issue as well.

  Regards,

Quoting Stanislav Sedov <stas@FreeBSD.org>:

> Hi, Mario!
>
> What's regarding the amd64 problem I asked before? Is it fixed?
> If you missed the prvious email, I'm including it here.
>
> Begin forwarded message:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Sat, 28 Feb 2009 09:19:26 -0300
> Mario Sergio Fujikawa Ferreira <lioux@FreeBSD.org> mentioned:
>
>> Hi,
>>
>>         I did some work on the lang/ruby18 to enable Profile-Guided
>> Optimization (PGO) build support.
>>
>>         What I did? (Steps 1-4 handled by pgo port target).
>>
>> ------- RECIPE
>>         1) Compile everything with CFLAGS/LDFLAGS containing
>>           '-fprofile-generate';
>>
>>         2) Run lots of test cases to generate profiling information
>>            (make check);
>>
>>         3) Remove all binaries leaving only the profiling information behind;
>>
>>         4) Replace all instances of '-fprofile-generate' with
>>            '-fprofile-use';
>>
>>         5) Re-compile everything using the profiling information.
>> -------
>>
>>         If I did it correctly, you should not notice any differences
>> on port usage aside from PGO option and a huge build compilation
>> time. Please, verify if you can that I did all steps of the "RECIPE"
>> correctly.
>>
>>         I am not a ruby expert so I would like input on this one:
>>
>>         1) Does it perform better than ruby18 compiled without PGO?
>>            Hard number benchmarks welcome. Check
>>            http://github.com/acangiano/ruby-benchmark-suite/tree/master
>>
>>         2) Also, could others run specification conformance
>>            verification checks on the resulting ruby interpreter?
>>            So that we have multiple cross verification. Perhaps,
>>            with rubyspec?
>>
>>         I hope you find this useful and that it performs as expected.
>> I want to go after lang/ruby19. Perhaps, even python and perl5.
>>
>>         The modified port file can be found at
>>
>> http://people.freebsd.org/~lioux/ruby18-pgo-2009022800.tbz[1]
>>
>> but the patch is so small that I have it as an attachment.
>>
>>         Regards,
>>
>> --
>> Mario S F Ferreira - DF - Brazil - "I guess this is a signature."
>> feature, n: a documented bug | bug, n: an undocumented feature
>>
>>
>> !DSPAM:49a92be2967008612027430!
>>
>
> Hi!
>
> Thanks for a great work. I'll look which benchmark suite I can intergrate
> into the port to profile ruby more precisely.
>
> BTW, is it supposed to work on amd64? I'm receiving the following:
> cc -shared -fprofile-generate -Wl,-soname,libruby18.so.18  array.o  
> bignum.o  class.o  compar.o  dir.o  dln.o  enum.o  enumerator.o  
> error.o  eval.o  file.o  gc.o  hash.o  inits.o  io.o  marshal.o  
> math.o  numeric.o  object.o  pack.o  parse.o  process.o  prec.o  
> random.o  range.o  re.o  regex.o  ruby.o  signal.o  sprintf.o  st.o  
> string.o  struct.o  time.o  util.o  variable.o  version.o   dmyext.o 
> -lcrypt -lm  -rpath=/usr/lib:/usr/local/lib -pthread  -o 
> libruby18.so.18
> /usr/bin/ld: /usr/lib/libgcov.a(_gcov_one_value_profiler.o): 
> relocation R_X86_64_32 can not be used when making a shared object; 
> recompile with -fPIC
> /usr/lib/libgcov.a: could not read symbols: Bad value
> *** Error code 1
>
> Guess we need a PIC version of gcov...
>
> - --
> Stanislav Sedov
> ST4096-RIPE
> -----BEGIN PGP SIGNATURE-----
>
> iEYEARECAAYFAknbEa4ACgkQK/VZk+smlYFL+wCeKNM6sCjKnvrmlJ/xvIui5bI1
> jH4Anizk6Apf3DZHIdbi5YXpiX5HRuT3
> =L3b3
> -----END PGP SIGNATURE-----
>
> Best regards,
> --
> Stanislav Sedov
> ST4096-RIPE
>
>

-- 
Mario S F Ferreira - DF - Brazil - "I guess this is a signature."
feature, n: a documented bug | bug, n: an undocumented feature

Links:
------
[1] http://people.freebsd.org/%7Elioux/ruby18-pgo-2009022800.tbz
Comment 5 Stanislav Sedov freebsd_committer freebsd_triage 2009-06-23 17:32:41 UTC
On Tue, 23 Jun 2009 13:24:23 -0300
Mario Sergio Fujikawa Ferreira <lioux@FreeBSD.org> mentioned:

> Hi,
> 
>   I do not think this is exclusive to PGO (profile guided optimization) builds. I am receiving the exact same error message on math/libjbigi (which is now marked broken because of this). It is not just recompiling with -fPIC. That did not fix math/libjbigi.
> 
> /usr/bin/ld: /usr/lib/libgcov.a(_gcov_one_value_profiler.o): relocation R_X86_64_32 can not be used when making a shared object; recompile with -fPIC
> 
>   Unfortunately, I do not have an amd64 FBSD install to pursue this one. I am not even sure how to begin. We might need someone knowledgeable on the gcc build toolchain.
> 
>   My suggestion would be (perhaps) checking math/libjibi 1st. It could be an easier target (very small build). We could fix that one 1st then try the same fix on lang/ruby18.
> 
>   However, I would require your assistance since I do not have a amd64 FBSD install.
> 
>   Incidentally, this is the exact same error message reported for the www/firefox3 PGO PR ports/132231. I am CCing the firefox3 maintainer so that he can follow this issue as well.
> 

Hi!

I tried to track the issue and it appears to be the bug in our amd64 gcov
build.  It was build without proper PIC flags set, but kan fixed this issue
on HEAD recently by my request.  I have not tested it yet, though.  I'll
try tomorrow's evening.

Best regards,
-- 
Stanislav Sedov
ST4096-RIPE
Comment 6 Mario Sergio Fujikawa Ferreira freebsd_committer freebsd_triage 2009-11-10 17:06:39 UTC
Quoting Stanislav Sedov <stas@FreeBSD.org>:

> On Tue, 23 Jun 2009 13:24:23 -0300
> Mario Sergio Fujikawa Ferreira <lioux@FreeBSD.org> mentioned:
>
>> Hi,
>>
>>   I do not think this is exclusive to PGO (profile guided 
>> optimization) builds. I am receiving the exact same error message on 
>> math/libjbigi (which is now marked broken because of this). It is 
>> not just recompiling with -fPIC. That did not fix math/libjbigi.
>>
>> /usr/bin/ld: /usr/lib/libgcov.a(_gcov_one_value_profiler.o): 
>> relocation R_X86_64_32 can not be used when making a shared object; 
>> recompile with -fPIC
>>
>>   Unfortunately, I do not have an amd64 FBSD install to pursue this 
>> one. I am not even sure how to begin. We might need someone 
>> knowledgeable on the gcc build toolchain.
>>
>>   My suggestion would be (perhaps) checking math/libjibi 1st. It 
>> could be an easier target (very small build). We could fix that one 
>> 1st then try the same fix on lang/ruby18.
>>
>>   However, I would require your assistance since I do not have a 
>> amd64 FBSD install.
>>
>>   Incidentally, this is the exact same error message reported for 
>> the www/firefox3 PGO PR ports/132231. I am CCing the firefox3 
>> maintainer so that he can follow this issue as well.
>>
>
> Hi!
>
> I tried to track the issue and it appears to be the bug in our amd64 gcov
> build.  It was build without proper PIC flags set, but kan fixed this issue
> on HEAD recently by my request.  I have not tested it yet, though.  I'll
> try tomorrow's evening.
>
> Best regards,
> --
> Stanislav Sedov
> ST4096-RIPE
>
>

-- 
Mario S F Ferreira - DF - Brazil - "I guess this is a signature."
feature, n: a documented bug | bug, n: an undocumented feature
Comment 7 Thomas Abthorpe freebsd_committer freebsd_triage 2011-11-05 04:11:44 UTC
Responsible Changed
From-To: stas->freebsd-ports-bugs

- back to the heap
Comment 8 Eitan Adler freebsd_committer freebsd_triage 2011-11-12 02:38:03 UTC
Responsible Changed
From-To: freebsd-ports-bugs->ruby

over to ruby
Comment 9 Philip M. Gollucci freebsd_committer freebsd_triage 2012-02-10 02:01:54 UTC
State Changed
From-To: open->closed

this option doesnt quite work