1

A very concrete question here. I have two sample foo2d.c files like this:

First,

#include <stdio.h>

__attribute__((visibility("default"))) void FooX(int i);

void Foo2(int i)
{
    printf("Via Foo2(%d)\n", i);
    FooX(i);
}

Second,

#include <stdio.h>

__attribute__((visibility("hidden"))) void FooX(int i);

void Foo2(int i)
{
    printf("Via Foo2(%d)\n", i);
    FooX(i);
}

The only difference is the visibility declaration of FooX.

Given the two files the same name and compile them twice(gcc -c foo2d.c), I got two .o files and rename them to be foo-default.o and foo-hidden.o respectively. I compare the two .o files and find out they differ by only one byte.

Beyond Compare showing the diff

I really want to know the meaning of the difference of this byte, from a relocatable object's perspective. Can objdump or readelf, or whatever standard tools tell the difference of them?

My experiment env is openSUSE Linux 11.4, gcc 4.5.1.

Jimm Chen
  • 3,411
  • 3
  • 35
  • 59

1 Answers1

2

the difference should be in the symbol table. A symbol's visibility is determined from its st_other field of the symtab entry. It says:

Name          value
STV_DEFAULT   0
STV_INTERNAL  1
STV_HIDDEN    2
STV_PROTECTED 3

Refer to http://docs.oracle.com/cd/E19683-01/816-1386/6m7qcoblj/index.html#chapter7-27

Add: you can dump the symtab to check:

    readelf -x .symtab foo-hidden.o
    objdump -t foo-hidden.o
tristan
  • 4,235
  • 2
  • 21
  • 45