ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Why does bloom `export LDFLAGS=`?

asked 2020-07-03 17:42:10 -0600

rubicks gravatar image

updated 2020-07-07 09:56:16 -0600

As of this writing, the bloom repository has at least one debian/rules template featuring the following comment:

# TODO: remove the LDFLAGS override.  It's here to avoid esoteric problems
# of this sort:
export LDFLAGS=


Those commented links are dead, and the internet archive wayback machine doesn't have them. The distant ancestor of that file already had those comments when it was added in 2012:

Does anyone remember what ROS trac tickets 2977 and 3842 were about? What were those "esoteric problems" mentioned by the author?


My ROS friends have pointed me toward catkin issue #72 and a commit referencing the same:

It's clear this LDFLAGS override has something to do with preventing the linker from seeing the -Bsymbolic-functions flag. More detail forthcoming as I dig into it.

_Update The Second_:

My further searching has led to several tickets reporting runtime segfaults caused by the use of -Bsymbolic-functions during the link phase:

It is the dpkg-buildflags command (of Ubuntu's dpkg-dev package) that adds -Bsymbolic-functions to the LDFLAGS during a normal dpkg-buildpackage:

root@c7dc18648a0e:/# cat /etc/ && dpkg-buildflags --get LDFLAGS
Ubuntu 20.04 LTS
-Wl,-Bsymbolic-functions -Wl,-z,relro

Note that the Debian dpkg-dev does _not_ do this:

root@b134afb3a682:/# cat /etc/ && dpkg-buildflags --get LDFLAGS
Debian GNU/Linux 10

The "proper" way to remove options from the set of linker flags is explained in man 1 dpkg-buildflags "Environment" section:

DEB_flag_STRIP DEB_flag_MAINT_STRIP This variable can be used to provide a space separated list of options that will be stripped from the set of flags returned for the given flag.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2020-07-06 19:35:47 -0600

gerkey gravatar image

After a trip into the basement where they keep the Ark of the Covenant, I found an email that I sent to Jeremy Leibs and Ken Conley looking for advice on this topic in February 2012:

John and I spent quite some time yesterday tracking down a segfault that was only happening when using a .deb built by our new catkin-based debbuilder, and could not be reproduced by compiling the crashing library from source. Turns out that we could reproduce it by building the library with -Wl,-Bsymbolic-functions on the link line. And that's what pbuilder is doing in the new debbuilder.

That whole sequence rang a distant bell in my mind, and I then found this gem of a ticket: So we've simply re-encountered the problem.

The space of solutions is the same, with the "right" answer likely being to force everybody to use -Wl,-Bsymbolic-functions in their own development, and fixing underlying bugs. But at this point, I don't have time before the Fuerte release to work through the regressions that would surely result.

So: do you recall how you "cleared out LDFLAGS in the current deb-building system"? I'd like to do the same in the new system.

We'll do our best to address this properly in the next release cycle, starting early.

What followed in the email thread amounted to, "yeah, it's best to add LDFLAGS= somewhere in the pipeline". The description of the resulting catkin issue is simply a copy and paste of Ken's response along those lines.

I do not recall what the actual problem was. After reading through this ancient history, my guess is:

  • Somewhere in the normal deb-building pipeline (at least when using pbuilder), somebody adds -Wl,-Bsymbolic-functions to LDFLAGS.
  • That addition is probably done for some good reason and it's probably not supposed to cause harm.
  • Unfortunately it can sometimes cause harm, probably by exposing some underlying bug or flawed assumption in the code that is being built into a deb.
  • We papered over the bug/flaw by wiping out LDFLAGS.
  • We intended to address the underlying bug/flaw but probably never made it happen.

Unfortunately, from the description that I gave to Ken and Jeremy, it seems like whatever problem arises when using -Wl,-Bsymbolic-functions may present itself as a tricky segfault. So my guess is that it's not safe to remove the LDFLAGS override. Or at least it would be hard to prove that it's safe.

edit flag offensive delete link more

answered 2020-07-23 20:23:22 -0600

tfoote gravatar image

Here's some background I manually dug out of the archives.

Ticket 2977




jfaust, wim, and myself have been perplexed by compiler flag behavior leading to heisenbugs: a package that fails to build successfully builds with a "make clean; make", probably due to different compiler flags. Also, the new compiler flags do not appear to be correct.

This is seen with pr2_ethercat_drivers, which fails to build in the new debbuild system:

The errors are of this form:
 Linking CXX executable ../motorconf
  Linking CXX shared library ../lib/
  CMakeFiles/motorconf.dir/src/wg0x.o: In function `realtime_tools::RealtimePublisher<pr2_msgs::PressureState_<std::allocator<void> > >::unlockAndPublish()':
  /opt/ros/unstable/stacks/pr2_mechanism/realtime_tools/include/realtime_tools/realtime_publisher.h:134: undefined reference to `boost::condition_variable::notify_one()'
  CMakeFiles/motorconf.dir/src/wg0x.o: In function `realtime_tools::RealtimePublisher<pr2_msgs::AccelerometerState_<std::allocator<void> > >::unlockAndPublish()':

and reproducible if you run:
sudo apt-get install pbuilder -y
rosrun rosdeb unstable pr2_ethercat_drivers lucid amd64 --interactive --force --noupload --noramdisk

When you initially load the system, you'll see the linker error. If you proceed to run:

export ROS_DESTDIR=/tmp/buildd/ros-unstable-pr2-ethercat-drivers-1.2.0/debian/ros-unstable-pr2-ethercat-drivers
. /tmp/buildd/ros-unstable-pr2-ethercat-drivers-1.2.0/
roscd ethercat_hardware
make clean; make

The error goes away. We've run this with "VERBOSE=1 make" to capture the build flags and seen that they are different. You'll also see that 'errorGood.txt' has '-O2', even though ethercat_hardware is set to "Debug" (separately ticketed).

I've attached 'errorBad.txt' and 'errorGood.txt'


y c 1 The difference between the two set of flags is that the bad build add
m Digging...

y c 2 Ok, I can reproduce the bad link line, though not the linker failure
m roscd ethercat_hardware
m make clean
LDFLAGS="-O2 -g -Wl,-Bsymbolic-functions" make VERBOSE=1
The LDFLAGS args get inserted in the same place near the beginning of
My hypothesis: inside the environment created by pbuilder, something
I would guess that you'll find the same flags in every link step, in
Perhaps those flags are part of Ubuntu's standard package-building sy
7 1 k c 3 I'll pass this off to Jeremy. My 1/4 of build engineer brain does not know about pbuilder

c 4 Googling around supports my hypothesis:
* "debuild/dpkg-buildpackage have system defaults for CFLAGS, CXXFLA
* "On Ubuntu (as of hardy), dpkg-buildpackage sets LDFLAGS to contai
2 1 g c 5 I'm inclined to say that, unless Debian/Ubuntu has been careless or controversial in the build

7 1 le c 6 So what seems to be this exact same bug led to another problem, which
2 ib o
8 s m We either need to disable these flags in the build system, or add the

c 7 Presumably it's `-Wl,-Bsymbolic-functions` that's causing the trouble
m That won't make everybody use it ...
edit flag offensive delete link more

Question Tools



Asked: 2020-07-03 17:42:10 -0600

Seen: 389 times

Last updated: Jul 23 '20