Why Ubuntu and openSUSE's GNU C program linker produce different mapfile?

23 views Asked by At

In brief, I find that running gcc on openSUSE does not produce a map file that shows me "As-needed library included to satisfy reference by file (symbol)" paragraph. I'm wondering why.

Lab environments:

  • Ubuntu 18.04, gcc 7.5.0, binutils 2.30 (2019-05-08)
  • openSUSE Leap 15.5, gcc 7.5.0, binutils 2.39 (2022-10-25)

A simple foo1.c:

#include <stdio.h>

extern void FooX(int);

void Foo1(int i)
{
        printf("foo1(%d)\n", i);
        i++;
        FooX(i);
}

The compile command is:

gcc foo1.c -fpic -shared -o libfoo1.so -Wl,-Map=foo1.map,--cref

This produces libfoo1.so and foo1.map .

On Ubuntu, I see at start of the mapfile:

As-needed library included to satisfy reference by file (symbol)

libc.so.6                     /tmp/cch6AxRm.o (printf@@GLIBC_2.2.5)

Ubuntu mapfile

It says that libc.so.6 is needed by my libfoo1.so, due to the latter needs printf symbol from the former.

However, doing the same on openSUSE 15.5 gives me different foo1.map which does NOT have the "As-needed library included to satisfy reference by file" information.

openSUSE mapfile

ChatGPT suggests that I add linker option --as-needed to openSUSE's gcc. I tried it, no effect.

I'm really curious, what makes the difference on the two Linux distros, or, can I force openSUSE to produce the as-needed info for me?

0

There are 0 answers