You are not logged in.

#1 2014-02-13 19:34:21

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,332
Website

[SOLVED] makepkg builds differently than local build

SOLUTION: my makefile with `CFLAGS += ...` did not pick up the local CFLAGS environment variable, with the command in my second post, my local build has the same issue as the makepkg build.
-----

I have a project of mine alopex which I'm polishing up a new version for.  I've been running a locally built version for a while, but when I installed it with makepkg I'm getting all sorts of memory errors and crashes when I run it.

The first obvious difference between my local build and makepkg was that makepkg strips the binary - so I stripped the local binary, but no change: the local build in ~/code/alopex/ worked fine, but the makepkg/pacman installed version in /usr/bin/ did not.

The next step was to source /etc/makepkg.conf for the local build to use all the same CFLAGS and LDFLAGS as a makepkg build.  But this also lead to no change in the results.

Here are the two files, both from the exact same git source, both built with makepkg.conf build flags, and both stripped.

$  ls -l /usr/bin/alopex 
-rwxr-xr-x 1 root root 48280 Feb 13 14:21 /usr/bin/alopex

$ file /usr/bin/alopex 
/usr/bin/alopex: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=03e8e16e7208d6c97bce6bd545f45d20c7a7606a, stripped

$ ls -l ~/code/alopex/alopex 
-rwxr-xr-x 1 jmcclure users 54760 Feb 13 14:30 /home/jmcclure/code/alopex/alopex

$ file ~/code/alopex/alopex 
/home/jmcclure/code/alopex/alopex: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=0659354ed5a904fe93894f14d6bd413ea278396e, stripped

I can't figure out why the binaries are difference sizes and have different checksums.  I suspect there is an error in my code that is only exposed when built with makepkg - but this is hard to track down without knowing what makepkg is doing differently than my local build.  To be sure relative paths couldn't be relevant, I also moved the locally built binary to /usr/bin/ (overwriting the makepkg/pacman one) and it executed just fine.

So - my main question is, in addition to stripping a binary and using the makepkg.conf flags, what else is different about the makepkg build and my local build?  I'm guessing it might have to do with makepkg using a clean chroot build environment (right?), but namcap doesn't detect any missing dependencies or any other issues.


-----------------------------------------------------------------------
Below are many details that may or may not be relevant
-----------------------------------------------------------------------

EDIT: in case it's relevant, here is the `env` output for the local build with only the PS1/PS2 and LS_COLORS removed as they are long and I can't imagine relevant.

XDG_VTNR=1
LESS_TERMCAP_mb=
XDG_SESSION_ID=1
LESS_TERMCAP_md=
LESS_TERMCAP_me=
TERM=rxvt-unicode-256color
SHELL=/bin/bash
WINDOWID=6291462
OLDPWD=/home/jmcclure
LESS_TERMCAP_ue=
USER=jmcclure
_JAVA_OPTIONS=-Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel
SYSTEMD_PAGER=
PAGER=vimpager
MOZ_PLUGIN_PATH=/usr/lib/mozilla/plugins
LESS_TERMCAP_us=
MAIL=/var/spool/mail/jmcclure
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/jmcclure/code/bin:/home/jmcclure/code/bin
HG=/usr/bin/hg
LC_COLLATE=C
PWD=/home/jmcclure/code/alopex
JAVA_HOME=/usr/lib/jvm/java-7-openjdk
EDITOR=vim
LANG=en_US.UTF-8 
HISTCONTROL=erasedups
COLORFGBG=default;default
SHLVL=2
XDG_SEAT=seat0
HOME=/home/jmcclure
TERMINFO=/usr/share/terminfo
XDG_CONFIG_HOME=/home/jmcclure/.config
_JAVA_AWT_WM_NONREPARENTING=1
LESS= -RXx4
LOGNAME=jmcclure
LESS_TERMCAP_so=
LESSOPEN=|/usr/bin/src-hilite-lesspipe.sh %s
td=
WINDOWPATH=2
XDG_RUNTIME_DIR=/run/user/1000
DISPLAY=:0
COLORTERM=rxvt
LESS_TERMCAP_se=
_=/usr/bin/env

As a temporary work-around, I found that the following produces a working binary and somehow avoids the step that is leading to the crashes

makepkg
cd src/alopex
make clean
make
cd ../..
makepkg -efi

I've been tinkering with readelf to see what differences I can pinpoint.  I really don't know what I'm doing, but it seemed the symbols (-s) and dynamic links (-d) were all the same between the two version except for the addressess/offsets/hex-number-column.  So I tried checking the readelf -h output and I get a couple differences there - in this output, the /usr/bin/alopex version is the working one:

diff <(readelf -h /tmp/alopex/pkg/alopex-git/usr/bin/alopex) <(readelf -h /usr/bin/alopex)
11c11
<   Entry point address:               0x4030d8
---
>   Entry point address:               0x403020
13c13
<   Start of section headers:          46488 (bytes into file)
---
>   Start of section headers:          52968 (bytes into file)
17c17
<   Number of program headers:         9
---
>   Number of program headers:         8

I'm not sure what these differences mean, but they are consistent with every working and non-working build.

Readelf -l output indicates that the extra program header in the nonworking version includes the following:

 08     .init_array .fini_array .jcr .dynamic .got

Each of these symbols exist in the working binary as well, but they are duplicated in the non-working version (still no idea what this actually means, but in case someone else can decode this ...)

Last edited by Trilby (2014-02-13 20:38:13)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Online

#2 2014-02-13 20:27:49

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] makepkg builds differently than local build

Trilby wrote:

As a temporary work-around, I found that the following produces a working binary and somehow avoids the step that is leading to the crashes

makepkg
cd src/alopex
make clean
make
cd ../..
makepkg -efi

I realize that you've stated that you've tried to build with the same flags, but your workaround strongly points at this being a {CPP,C,LD}FLAGS issue. I'd suggest comparing the compile commands used between the 2 different builds.

<snarky>
Have you tried fixing your crashes?
</snarky>

Last edited by falconindy (2014-02-13 20:28:26)

Offline

#3 2014-02-13 20:34:12

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,332
Website

Re: [SOLVED] makepkg builds differently than local build

Crap - you are, of course, right.  It seems my Makefile is not doing what I thought it was.  I define makefile variables for flags with += operators, which I thought picked up the current value from the environment.  But it seems not to do this.

I plan to fix the crashes, but I was stumped, and I wanted to know why it worked in some builds and not others - I'm hoping this information will help narrow down what my coding error is.

EDIT: a local build with `CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" make` reproduces the error.

Thanks for the help - now I know which flags expose my error, so I may be able to narrow it down.

FOLLOW-UP: Thanks again - while I have no doubt that my troubleshooting steps are unconventional (as I have no 'conventional' training in programming) this did allow me to track down a bug in my code which I had been missing.

Last edited by Trilby (2014-02-13 23:03:54)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Online

#4 2014-02-13 22:47:19

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] makepkg builds differently than local build

Hrm. There's a lot you could do to simplify your Makefile and lean on the built in rules. The thing that stands out the most is the separate rules for compilation and linking. Really, you can condense that all into:

$(PROG): $(MODULES:%=%.o)

No commands are needed -- the rule name and dependencies are enough to trigger the built-in rules for .c -> .o and .o -> $binary.

Offline

#5 2014-02-13 22:52:57

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,332
Website

Re: [SOLVED] makepkg builds differently than local build

Thanks, that works well - but if you don't mind the OT, that leaves all the object files in the top level directory.  Of course `make clean` can get rid of these, but I liked the orderliness of having them tucked away in the /src directory.  I know I could also use separate make files in the subdirectory/ies, but this always seemed to be more of a hassle than it was worth.

EDIT: nevermind that, I went with a more proper clean directive that leaves the final binary alone, and added distclean for getting rid of that to.  Now the location of the object files are no concern.  Thanks again.

Last edited by Trilby (2014-02-13 23:00:54)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Online

Board footer

Powered by FluxBB