Skip to content

Localize hostname symbol #1281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andig opened this issue Dec 22, 2015 · 12 comments
Closed

Localize hostname symbol #1281

andig opened this issue Dec 22, 2015 · 12 comments

Comments

@andig
Copy link
Contributor

andig commented Dec 22, 2015

When I declare

String hostname;

I end up with a compiler conflict:

C:\Users\xx\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.0.0-rc2/tools/sdk/lib\libmain.a(eagle_lwip_if.o):(.bss+0x0): multiple definition of `hostname'

sketch\esp8266-webconf.ino.cpp.o:(.bss.hostname+0x0): first defined here

c:/users/xx/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: Warning: size of symbol `hostname' changed from 12 in sketch\esp8266-webconf.ino.cpp.o to 4 in C:\Users\xx\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.0.0-rc2/tools/sdk/lib\libmain.a(eagle_lwip_if.o)

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling.

However, when I try to use the obviously existing internal hostname I receive an undefined error.

Is hostname a forbidden symbol name?

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@igrr
Copy link
Member

igrr commented Dec 22, 2015

hostname is a symbol exported from one of SDK libraries. When you declare
another symbol with the same name, you get linker error. If you try to use
the existing one you get compiler error, because hostname isn't declared
anywhere.

For now, you should avoid using this name.
I'll check if it can be localized to one of the libraries.

On Tue, Dec 22, 2015, 19:04 andig notifications@github.com wrote:

When I declare

String hostname;

I end up with a compiler conflict:

C:\Users\xx\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.0.0-rc2/tools/sdk/lib\libmain.a(eagle_lwip_if.o):(.bss+0x0): multiple definition of `hostname'

sketch\esp8266-webconf.ino.cpp.o:(.bss.hostname+0x0): first defined here

c:/users/xx/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: Warning: size of symbol `hostname' changed from 12 in sketch\esp8266-webconf.ino.cpp.o to 4 in C:\Users\xx\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.0.0-rc2/tools/sdk/lib\libmain.a(eagle_lwip_if.o)

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling.

However, when I try to use the obviously existing internal hostname I
receive an undefined error.

Is hostname a forbidden symbol name?


Reply to this email directly or view it on GitHub
#1281.

@igrr igrr changed the title Clarification: use of hostname symbol? Localize hostname symbol Feb 29, 2016
@igrr igrr added this to the 2.2.0 milestone Feb 29, 2016
@igrr igrr modified the milestones: 2.2.0, 2.3.0 Apr 18, 2016
@igrr igrr modified the milestones: 2.3.0, 2.4.0 Jun 3, 2016
@devyte
Copy link
Collaborator

devyte commented Oct 19, 2017

@d-a-v does #3362 fix this? I can't find the symbol in lwip2.

@devyte devyte added the waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. label Oct 19, 2017
@d-a-v
Copy link
Collaborator

d-a-v commented Oct 19, 2017

hostname is defined (not referred) and uninitialized in libmain.a.

$ nm libmain.a
[...]
00000000 B hostname
[...]
$ man nm
[...]
           "B"
           "b" The symbol is in the uninitialized data section (known as BSS).
[...]

I'm not sure who uses it nor who should initialize it.
But one can definitely not declare a new global "C" one (except if declared as static).

@devyte
Copy link
Collaborator

devyte commented Nov 20, 2017

@igrr said:

I'll check if it can be localized to one of the libraries.

What does this mean? Did you ever get around to looking into it?

@igrr
Copy link
Member

igrr commented Dec 27, 2017

hostname seems to be also defined in lwip2 now:

tools/sdk/lib/liblwip2.a:lwip-git.o:00000000 b hostname

@devyte
Copy link
Collaborator

devyte commented Dec 28, 2017

@igrr you know, this can be avoided with an anonymous namespace, which is recommended C++ style anyways (put user globals in an anonymous namespace in the .ino). Whatever else we do for this issue, that should be our recommendation for usage of globals anyways.

@d-a-v
Copy link
Collaborator

d-a-v commented Dec 28, 2017

@igrr hostname in lwip2 was not used and is not anymore present in sources.
The hostname defined in libmain.a is probably used by wifi_station_get/set_hostname().

@devyte
Copy link
Collaborator

devyte commented Dec 28, 2017

@d-a-v @igrr :

develo@esp:~/workspace/arduino/hardware/esp8266com/esp8266/tools/sdk/lwip2/builder$ nm liblwip2.a |grep hostname
00000000 b hostname
...
develo@esp:~/workspace/arduino/hardware/esp8266com/esp8266/tools/sdk/lwip2/builder$ grep -r -n hostname .
...
./glue-lwip/lwip-git.c:50:static char hostname[32];
...
develo@esp:~/workspace/arduino/hardware/esp8266com/esp8266/tools/sdk/lwip2$ nm /tmp/arduino_build_356920/espora.ino.elf  |grep hostname
...
3fff1740 b hostname
3ffefab4 B hostname
...

I looks like now we have 2 hostname symbols...

@d-a-v
Copy link
Collaborator

d-a-v commented Dec 28, 2017

After current lwip2 PR there will be only one.

@devyte
Copy link
Collaborator

devyte commented Dec 28, 2017

Ok, so we're back to the initial issue: the hostname symbol likely coming from the SDK.
@igrr said:

I'll check if it can be localized to one of the libraries.

What can be done?

@igrr
Copy link
Member

igrr commented Dec 28, 2017

Ok, if the hostname symbol does not have to be shared between libmain and lwip, I'll just make it local in the object file where it is defined.

igrr added a commit that referenced this issue Dec 31, 2017
hostname -> wifi_station_hostname
default_hostname -> wifi_station_default_hostname
@igrr
Copy link
Member

igrr commented Dec 31, 2017

Resolved in 8edeac0.

Localizing the symbols was not possible (they were used in two object files), so i added wifi_station_ prefix to both hostname and default_hostname.

@igrr igrr added staged-for-release and removed waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. labels Dec 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants