https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104895

            Bug ID: 104895
           Summary: lto1: issue with space in library filename
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: christophm30 at gmail dot com
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

When building Souffle, I ran into an LTO issue with a library that contains a
space in its filename (see
https://github.com/souffle-lang/souffle/issues/2214).

I've isolated the issue as follows (Fedora 35: gcc (GCC) 11.2.1 20220127 (Red
Hat 11.2.1-9)):

Makefile:
CC=gcc
CFLAGS=-fPIC
CFLAGS:=$(CFLAGS) -flto=auto
RM=rm -f
all: ltomain

"lib do it".so: doit.o
        $(CC) $(CFLAGS) $(LDFLAGS) -shared -Wl,-soname,"lib'do it'.so" -o
"lib'do it'.so" doit.o

ltomain: main.o "lib do it".so
        $(CC) $(CFLAGS) $(LDFLAGS) -o $@ main.o -L. -l"'do it'"
clean:
        $(RM) *.o *.so ltomain

doit.c:
#include <stdio.h>
void doit(void)
{
  printf("Hello world!\n");
}
void doit();

main.c:
int main()
{
  doit();
}

This gives the following error:
$ make clean all
rm -f *.o *.so ltomain
gcc -fPIC -flto=auto   -c -o main.o main.c
gcc -fPIC -flto=auto   -c -o doit.o doit.c
gcc -fPIC -flto=auto  -shared -Wl,-soname,"lib'do it'.so" -o "lib'do it'.so"
doit.o
lto1: error: open it.so. failed: No such file or directory
make[1]: *** [/tmp/ccetIqO9.mk:2: /tmp/ccIqDtkB.ltrans0.ltrans.o] Error 1
lto-wrapper: fatal error: make returned 2 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
make: *** [Makefile:9: "lib] Error 1

Replacing '-flto=auto' by '-flto' works:
$ make clean all
rm -f *.o *.so ltomain
gcc -fPIC -flto   -c -o main.o main.c
gcc -fPIC -flto   -c -o doit.o doit.c
gcc -fPIC -flto  -shared -Wl,-soname,"lib'do it'.so" -o "lib'do it'.so" doit.o
gcc -fPIC -flto  -shared -Wl,-soname,"lib'do it'.so" -o "lib'do it'.so" doit.o
gcc -fPIC -flto  -shared -Wl,-soname,"lib'do it'.so" -o "lib'do it'.so" doit.o
gcc -fPIC -flto  -o ltomain main.o -L. -l"'do it'"

$ LD_LIBRARY_PATH=. ./ltomain
Hello world!

Reply via email to