Bug 192501 - security/libtomcrypt - add fpic flag
Summary: security/libtomcrypt - add fpic flag
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Many People
Assignee: Tijl Coosemans
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-08 06:19 UTC by Oleksii Samorukov
Modified: 2014-08-08 16:39 UTC (History)
2 users (show)

See Also:


Attachments
add -fpic flag (572 bytes, patch)
2014-08-08 06:19 UTC, Oleksii Samorukov
no flags Details | Diff
proposed patch (4.24 KB, patch)
2014-08-08 13:15 UTC, Tijl Coosemans
no flags Details | Diff
patch2 (4.76 KB, patch)
2014-08-08 14:36 UTC, Tijl Coosemans
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Oleksii Samorukov freebsd_committer 2014-08-08 06:19:59 UTC
Created attachment 145504 [details]
add -fpic flag

I was trying to build program depending on libtomcrypt and found that build failed on amd64 because libtomcrypt is built w/o fpic flag. After adding it to libtomcrypt makefule build was successful.
Comment 1 John Marino freebsd_committer 2014-08-08 08:24:42 UTC
Shouldn't this be applied only to arch amd64?
Comment 2 Oleksii Samorukov freebsd_committer 2014-08-08 09:52:50 UTC
(In reply to John Marino from comment #1)
> Shouldn't this be applied only to arch amd64?

I don't really now. When i was grepping fpic on different makefiles i found both approaches - for amd64 only or for all platforms. And i don't really know if fpic on other platforms will/can make a problems.
Comment 3 John Marino freebsd_committer 2014-08-08 10:02:56 UTC
I think it's amd64 only.
You can test this on i386, try building your program without modifying  libtomcrypt, it should work.

Or if you don't want to test, just modify this to be AMD64 only, e.g. CFLAGS_amd64= -fPIC

e.g. http://svnweb.freebsd.org/ports/head/devel/libcfg/Makefile?revision=345872&view=markup
Comment 4 Tijl Coosemans freebsd_committer 2014-08-08 10:44:23 UTC
Please don't add -fPIC like that.  It'll cause static libraries and executables to be build with as well and that's wrong.  Problems with -fPIC are almost always because a configure test fails, so please search config.log for -fPIC and see if there are any problems there.
Comment 5 Oleksii Samorukov freebsd_committer 2014-08-08 11:53:21 UTC
(In reply to Tijl Coosemans from comment #4)
> Please don't add -fPIC like that.  It'll cause static libraries and
> executables to be build with as well and that's wrong.  Problems with -fPIC
> are almost always because a configure test fails, so please search
> config.log for -fPIC and see if there are any problems there.

In this case it's causing link error on the third party software depending on this tool. As far as i could see this port generating only .a library:

root@bsd10:~ # pkg info -l libtomcrypt-1.17_2|grep -v include
libtomcrypt-1.17_2:
	/usr/local/lib/libtomcrypt.a


so i think that patch is ok. I am ok to apply it only to amd64 if needed.
Comment 6 Oleksii Samorukov freebsd_committer 2014-08-08 11:54:01 UTC
(In reply to John Marino from comment #3)
> I think it's amd64 only.
> You can test this on i386, try building your program without modifying 
> libtomcrypt, it should work.
> 
> Or if you don't want to test, just modify this to be AMD64 only, e.g.
> CFLAGS_amd64= -fPIC
> 
> e.g.
> http://svnweb.freebsd.org/ports/head/devel/libcfg/
> Makefile?revision=345872&view=markup

I am ok to apply it as CFLAGS_amd64= -fPIC. Should i submit new patch?
Comment 7 Tijl Coosemans freebsd_committer 2014-08-08 12:16:41 UTC
I'm looking into building a shared library of libtomcrypt.
Comment 8 Tijl Coosemans freebsd_committer 2014-08-08 13:15:41 UTC
Created attachment 145521 [details]
proposed patch

Does this patch work for you?
Comment 9 Oleksii Samorukov freebsd_committer 2014-08-08 13:52:31 UTC
(In reply to Tijl Coosemans from comment #8)
> Created attachment 145521 [details]
> proposed patch
> 
> Does this patch work for you?

No, its not. Configure failing:

Package libtomcrypt was not found in the pkg-config search path.
Perhaps you should add the directory containing `libtomcrypt.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libtomcrypt', required by 'world', not found
configure:12728: $? = 1
configure:12840: checking if libtomcrypt is usable
configure:12853: cc -o conftest -I/usr/local/include   -L/usr/local/lib conftest.c  -ltomcrypt >&5
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_prime_is_prime'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_mulmod'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_mul_d'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_div_2'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_sqrmod'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_copy'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_cnt_lsb'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_sqr'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_to_unsigned_bin'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_invmod'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_exptmod'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_mul'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_add_d'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_montgomery_reduce'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_mod_d'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_sub'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_gcd'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_div'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_clear'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_get_int'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_montgomery_setup'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_cmp'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_read_radix'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_count_bits'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_add'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_lcm'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_unsigned_bin_size'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_read_unsigned_bin'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_toradix'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_set_int'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_2expt'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_cmp_d'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_neg'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_init'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_montgomery_calc_normalization'
/usr/local/lib/libtomcrypt.so: undefined reference to `mp_sub_d'
cc: error: linker command failed with exit code 1 (use -v to see invocation)
configure:12853: $? = 1


Just in case, i am checking with stoken tool, you can try it on your own as well.
Comment 10 Tijl Coosemans freebsd_committer 2014-08-08 14:36:39 UTC
Created attachment 145525 [details]
patch2

New patch.  Dependencies should be linked in now.
Comment 11 Oleksii Samorukov freebsd_committer 2014-08-08 16:06:30 UTC
(In reply to Tijl Coosemans from comment #10)
> Created attachment 145525 [details]
> patch2
> 
> New patch.  Dependencies should be linked in now.

Confirmed - works, and according to ldd linked with correct library:

$ ldd stoken
stoken:
	libstoken.so.1 => not found (0)
	libtomcrypt.so.0 => /usr/local/lib/libtomcrypt.so.0 (0x800821000)
	libxml2.so.2 => /usr/local/lib/libxml2.so.2 (0x800ab8000)
	libc.so.7 => /lib/libc.so.7 (0x800e38000)
	libz.so.6 => /lib/libz.so.6 (0x8011d1000)
	liblzma.so.5 => /usr/lib/liblzma.so.5 (0x8013e6000)
	libm.so.5 => /lib/libm.so.5 (0x801609000)
Comment 12 commit-hook freebsd_committer 2014-08-08 16:35:50 UTC
A commit references this bug:

Author: tijl
Date: Fri Aug  8 16:35:35 UTC 2014
New revision: 364372
URL: http://svnweb.freebsd.org/changeset/ports/364372

Log:
  Build shared library and simplify DOCS option

  PR:		192501
  Tested by:	samm@os2.kiev.ua

Changes:
  head/security/libtomcrypt/Makefile
  head/security/libtomcrypt/files/
  head/security/libtomcrypt/pkg-plist