[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug ld/19161] GNU ld wrongly garbage collects section referenced via __
From: |
tmsriram at google dot com |
Subject: |
[Bug ld/19161] GNU ld wrongly garbage collects section referenced via __start_SECTIONNAME |
Date: |
Thu, 22 Oct 2015 17:53:14 +0000 |
https://sourceware.org/bugzilla/show_bug.cgi?id=19161
Sriraman Tallam <tmsriram at google dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |tmsriram at google dot com
--- Comment #1 from Sriraman Tallam <tmsriram at google dot com> ---
(In reply to David Li from comment #0)
> Here is a small reproducible:
>
> // Failed with gnu ld
>
> gcc -fuse-ld=bfd -fdata-sections -Wl,--gc-sections gctest.c gctest2.c
>
> /tmp/cc4jxArE.o: In function `dump':
> gctest2.c:(.text+0xc): undefined reference to `__start_my_section'
gold linker has this check to prevent any named section 'XXX' from being
garbage collected if it finds a symbol __start_XXX or __stop_XXX:
In gold/gc.h:
//If the symbol name matches '__start_XXX' then the section with
// the C identifier like name 'XXX' should not be garbage collected.
// A similar treatment to symbols with the name '__stop_XXX'.
if (is_prefix_of(cident_section_start_prefix, gsym->name()))
{ ...
GNU ld should also be doing this?
> collect2: error: ld returned 1 exit status
>
>
> // Fine with Gold:
>
> gcc -fuse-ld=gold -fdata-sections -Wl,--gc-sections gctest.c gctest2.c
>
>
>
>
> // gctest.c
>
> extern int variable;
> int main()
> {
> return variable;
> }
>
>
> // gctest2.c
>
> typedef struct A {
> int i;
> int j;
> } A;
>
> extern int printf(const char*,...);
> extern int atexit(void (*)(void));
> A __attribute__((section("my_section"))) a[2] = {{1,2}, {3,4}};
>
> extern A __start_my_section;
> extern A __stop_my_section;
>
> int variable = 0;
>
>
> void dump()
> {
> A* ap = &__start_my_section;
> printf("%d %d\n", ap->i, ap->j);
> }
>
> void __attribute__((constructor)) foo() {
> atexit(dump);
> }
--
You are receiving this mail because:
You are on the CC list for the bug.
- [Bug ld/19161] New: GNU ld wrongly garbage collects section referenced via __start_SECTIONNAME, xinliangli at gmail dot com, 2015/10/21
- [Bug ld/19161] GNU ld wrongly garbage collects section referenced via __start_SECTIONNAME, xinliangli at gmail dot com, 2015/10/22
- [Bug ld/19161] GNU ld wrongly garbage collects section referenced via __start_SECTIONNAME,
tmsriram at google dot com <=
- [Bug ld/19161] GNU ld wrongly garbage collects section referenced via __start_SECTIONNAME, hjl.tools at gmail dot com, 2015/10/22
- [Bug ld/19161] GNU ld wrongly garbage collects section referenced via __start_SECTIONNAME, xinliangli at gmail dot com, 2015/10/22
- [Bug ld/19161] GNU ld wrongly garbage collects section referenced via __start_SECTIONNAME, cvs-commit at gcc dot gnu.org, 2015/10/22
- [Bug ld/19161] GNU ld wrongly garbage collects section referenced via __start_SECTIONNAME, hjl.tools at gmail dot com, 2015/10/22
- [Bug ld/19161] GNU ld wrongly garbage collects section referenced via __start_SECTIONNAME, cvs-commit at gcc dot gnu.org, 2015/10/22
- [Bug ld/19161] GNU ld wrongly garbage collects section referenced via __start_SECTIONNAME, cvs-commit at gcc dot gnu.org, 2015/10/23