ld --as-needed breaks implicit rules in make
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
make-dfsg (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
The default use of --as-needed with ld in oneiric breaks some implicit rules used by make. These rules invoke cc with command line in which $(LDFLAGS) appears before the source file being compiled or object file being linked, and that order is preserved when cc invokes ld. As a result, ld thinks the libraries listed in LDFLAGS aren't needed and doesn't link them.
For example, consider a C source file, example.c:
#include "zlib.h"
int main() {
inflateInit(0);
}
and a Makefile:
LDFLAGS = -lz
example: example.o
Running make invokes make's implicit rule for linking a single object file ("$(CC) $(LDFLAGS) n.o $(LOADLIBES) $(LDLIBS)"), and produces the following output:
cc -c -o example.o example.c
cc -lz example.o -o example
/tmp/ccovHoBb.o: In function `main':
example.
collect2: ld returned 1 exit status
make: *** [example] Error 1
Behind the scenes, ld is being run as "ld --as-needed ... -lz example.o ...". When ld processes libz, it doesn't know about any of the references from example.o, so it doesn't include it.
This problem seems to have prevented at least one package (sawfish-pager) from being included in oneiric because it would no longer compile, and I worry that there may be others.
I'm not sure what the best solution would be. One possibility would be patching make to change its implicit rules, but that could have serious consequences elsewhere. At the very least, it would necessitate patching other programs that run UNIX makefiles, such as remake and pmake.
affects: | make (Ubuntu) → make-dfsg (Ubuntu) |
So my reading is what you're saying is that the implicit rules in make need changing to match the use of --as-needed?