Bug 1540262 - libpfm: Does not use RPM build flags
Summary: libpfm: Does not use RPM build flags
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: libpfm
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: William Cohen
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: Fedora28BuildFlags
TreeView+ depends on / blocked
 
Reported: 2018-01-30 16:15 UTC by Florian Weimer
Modified: 2018-02-26 16:54 UTC (History)
3 users (show)

Fixed In Version: libpfm-4.9.0-6.fc29
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-02-26 16:54:04 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Florian Weimer 2018-01-30 16:15:38 UTC
libpfm-4.9.0-2.fc28 was not built with the official Fedora build flags from redhat-rpm-config:

make[1]: Entering directory '/builddir/build/BUILD/libpfm-4.9.0/lib'
cc  -g -Wall -Werror -Wextra -Wno-unused-parameter -I. -I/builddir/build/BUILD/libpfm-4.9.0/lib/../include -DCONFIG_PFMLIB_DEBUG -DCONFIG_PFMLIB_OS_LINUX -D_REENTRANT -I. -fvisibility=hidden -DCONFIG_PFMLIB_ARCH_X86 -DCONFIG_PFMLIB_ARCH_X86_64 -I. -c pfmlib_common.c

In the spec file, I do not see any attempt to inject $RPM_OPT_FLAGS or $RPM_LD_FLAGS into the build.

Comment 1 William Cohen 2018-01-30 22:15:39 UTC
Patched the libpfm.spec to pass in the %{optflags}.  However, builds showed that the new compiler checks enabled would flag some snprintf functions as possibly being truncated.  Submitted a patch for upstream review to check the snprintf return value to detect truncation during runtime:

https://sourceforge.net/p/perfmon2/mailman/message/36210397/

Tried scratch builds with the proposed libpfm patch, but the i686 builds fail due to an internal gcc compiler error (rhbz1538648).

Comment 2 Florian Weimer 2018-01-30 22:18:48 UTC
(In reply to William Cohen from comment #1)
> Patched the libpfm.spec to pass in the %{optflags}.  However, builds showed
> that the new compiler checks enabled would flag some snprintf functions as
> possibly being truncated.  Submitted a patch for upstream review to check
> the snprintf return value to detect truncation during runtime:
> 
> https://sourceforge.net/p/perfmon2/mailman/message/36210397/

Thanks!  (opendir allocates internally anyway, so you could perhaps use asprintf and do away with the explicit length management.)

> Tried scratch builds with the proposed libpfm patch, but the i686 builds
> fail due to an internal gcc compiler error (rhbz1538648).

Got a link to the scratch build?  There should be a workaround for that one in the current rawhide buildroot.

Comment 3 William Cohen 2018-01-30 22:34:59 UTC
Thanks for the comments about the libpfm upstream patch.

I tried another koji scratch build and it still fails as of 5:30pm EST.

https://koji.fedoraproject.org/koji/taskinfo?taskID=24578435

Comment 4 Florian Weimer 2018-01-31 07:34:45 UTC
(In reply to William Cohen from comment #3)
> Thanks for the comments about the libpfm upstream patch.
> 
> I tried another koji scratch build and it still fails as of 5:30pm EST.
> 
> https://koji.fedoraproject.org/koji/taskinfo?taskID=24578435

This is due to the captured build flags for building Python modules.  We need to rebuild python2 to pick up the new build flags, but we currently can't due to bug 1540316.  (We also have a real fix for GCC upstream now, which will make it into Fedora soon.)

Comment 5 William Cohen 2018-02-01 15:23:10 UTC
Built libpfm-4.9.0-4.fc28 in rawhide now.

Comment 6 Florian Weimer 2018-02-26 11:48:05 UTC
This is partially unfixed.

# rpm -qf /lib64/libpfm.so.4.9.0
libpfm-4.9.0-5.fc28.x86_64
# checksec --file /lib64/libpfm.so.4.9.0 
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH      FORTIFY Fortified Fortifiable  FILE
Partial RELRO   Canary found      NX enabled    DSO             No RPATH   No RUNPATH   Yes     7               11      /lib64/libpfm.so.4.9.0

Should be “Full RELRO”, not “Partial RELRO”.

There are no LDFLAGS on the linker command line:

cc -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -mcet -fcf-protection -g -Wall -Werror -Wextra -Wno-unused-parameter -I. -I/builddir/build/BUILD/libpfm-4.9.0/lib/../include -DCONFIG_PFMLIB_DEBUG -DCONFIG_PFMLIB_OS_LINUX -D_REENTRANT -I. -fvisibility=hidden -DCONFIG_PFMLIB_ARCH_X86 -DCONFIG_PFMLIB_ARCH_X86_64 -I.  -shared -Wl,-soname -Wl,libpfm.so.4  -o libpfm.so.4.9.0 pfmlib_common.lo […]

See https://src.fedoraproject.org/rpms/redhat-rpm-config/blob/master/f/buildflags.md for information on RPM macros and environment variables provided by the build environment.

Comment 7 William Cohen 2018-02-26 16:54:04 UTC
Should be fixed in libpfm-4.9.0-6.fc29 also merged the libpfm.spec fix into f28 branch.  Now have the following in the library:

$ checksec --file /lib64/libpfm.so.4.9.0 
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH	FORTIFY	Fortified Fortifiable  FILE
Full RELRO      Canary found      NX enabled    DSO             No RPATH   No RUNPATH   Yes	7		11	/lib64/libpfm.so.4.9.0


Note You need to log in before you can comment on or make changes to this bug.