Skip to content

cannot find entry symbol _start #216

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
nickdesaulniers opened this issue Oct 15, 2018 · 11 comments
Closed

cannot find entry symbol _start #216

nickdesaulniers opened this issue Oct 15, 2018 · 11 comments
Assignees
Labels
[ARCH] x86_64 This bug impacts ARCH=x86_64 [BUG] linux A bug that should be fixed in the mainline kernel. [FIXED][LINUX] 5.5 This bug was fixed in Linux 5.5 Needs Backport Should be backported to either linux-stable tree or latest llvm release branch. [TOOL] lld The issue is relevant to LLD linker

Comments

@nickdesaulniers
Copy link
Member

  LD      arch/x86/realmode/rm/realmode.elf
ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

This is with a few workarounds in place to link with LLD, so I wouldn't be surprise if once they're fixed, this quickly becomes unreproducible.

@nickdesaulniers nickdesaulniers added [BUG] Untriaged Something isn't working [ARCH] x86_64 This bug impacts ARCH=x86_64 [TOOL] lld The issue is relevant to LLD linker low priority This bug is not critical and not a priority labels Oct 15, 2018
@nickdesaulniers
Copy link
Member Author

nickdesaulniers commented Dec 10, 2018

lld/ELF/Writer.cpp:

// The entry point address is chosen in the following ways.
//
// 1. the '-e' entry command-line option;
// 2. the ENTRY(symbol) command in a linker control script;
// 3. the value of the symbol _start, if present;
// 4. the number represented by the entry symbol, if it is a number;
// 5. the address of the first byte of the .text section, if present;
// 6. the address 0.
static uint64_t getEntryAddr() {
  // Case 1, 2 or 3
  if (Symbol *B = Symtab->find(Config->Entry))
    return B->getVA();

  // Case 4
  uint64_t Addr;
  if (to_integer(Config->Entry, Addr))
    return Addr;

  // Case 5
  if (OutputSection *Sec = findSection(".text")) {
    if (Config->WarnMissingEntry)
      warn("cannot find entry symbol " + Config->Entry + "; defaulting to 0x" +
           utohexstr(Sec->Addr));
    return Sec->Addr;
  }

  // Case 6
  if (Config->WarnMissingEntry)
    warn("cannot find entry symbol " + Config->Entry +
         "; not setting start address");
  return 0;
}

So I assume the kernel does one of the above for arm64, which is why we don't see this warning there. Maybe we just need to do that for x86_64 as well?

Or just disable the warning if the resulting code is still correct.

@nickdesaulniers
Copy link
Member Author

$ nm vmlinux | grep 'T _start$'
$ readelf -t vmlinux | grep text
  [ 1] .text
       PROGBITS               PROGBITS         ffffffff81000000  0000000000200000  0
       0000000000e01941 0000000000000000  0                 4096
       [0000000000000006]: ALLOC, EXEC

So maybe just best to disable the warning?

lld/ELF/Driver.cpp has:

  Config->WarnMissingEntry =
      (!Config->Entry.empty() || (!Config->Shared && !Config->Relocatable));

but I'm not sure how to set Config->Entry.empty(). -e '' just presents the error:

ld.lld: error: cannot find linker script -e

cc @rui314 @GeorgiiR

@ghost
Copy link

ghost commented Dec 11, 2018

Is it possible to get the LLD --reproduce file for this?

(Actually, we use the getEntryAddr() value for ELF file header:
https://github.com/llvm-mirror/lld/blob/master/ELF/Writer.cpp#L2348
I wonder what is the GNU linkers behavior is, I would expect to see a warning too).

@dileks
Copy link
Collaborator

dileks commented Mar 3, 2019

I guess this needs an addition of -z max-page-size=4096 (Hex for 0x1000) in LDFLAGS_realmode.elf line in arch/x86/realmode/rm/Makefile.

UPDATE: This did not work.

@ms178
Copy link

ms178 commented Jul 30, 2019

By the way, I can still reproduce this warning with -O2, linux-next-next-20190730, clang version 10.0.0 (366783) and lld.

For the config and buildlog see #623

@tpgxyz
Copy link

tpgxyz commented Sep 23, 2019

Still occurs with kernel 5.3.1 and LLVM/clang-9.0.0 on x86_64

BUILDSTDERR: ld.lld: warning: -r and --gc-sections may not be used together, disabling --gc-sections
BUILDSTDERR: ld.lld: warning: -r and --icf may not be used together, disabling --icf
  LD      arch/x86/realmode/rm/realmode.elf
BUILDSTDERR: ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000
  RELOCS  arch/x86/realmode/rm/realmode.relocs

@nickdesaulniers
Copy link
Member Author

nickdesaulniers commented Sep 23, 2019

arch/x86/realmode/rm/Makefile:

 49 LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -T                
 50 CPPFLAGS_realmode.lds += -P -C -I$(objtree)/$(obj)                              

Sounds like maybe an ENTRY(<symbol>) in arch/x86/realmode/rm/realmode.lds.S would help?

$ make CC=clang -j71 defconfig
$ make CC=clang -j71
$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

https://lore.kernel.org/r/[email protected]/

@nickdesaulniers nickdesaulniers self-assigned this Sep 23, 2019
@nickdesaulniers nickdesaulniers added [BUG] linux A bug that should be fixed in the mainline kernel. [PATCH] Submitted A patch has been submitted for review and removed [BUG] Untriaged Something isn't working labels Sep 23, 2019
fengguang pushed a commit to 0day-ci/linux that referenced this issue Sep 23, 2019
Linking with ld.lld via $ make LD=ld.lld produces the warning:
ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Linking with ld.bfd shows the default entry is 0x1000:
$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly,
instead of depending on the implicit default.

Link: ClangBuiltLinux#216
Signed-off-by: Nick Desaulniers <[email protected]>
@nickdesaulniers
Copy link
Member Author

nickdesaulniers commented Sep 24, 2019

@tpimh
Copy link

tpimh commented Oct 1, 2019

https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=6a181e333954a26f46596b36f82abd14743570fd

@tpimh tpimh added [PATCH] Accepted A submitted patch has been accepted upstream and removed [PATCH] Submitted A patch has been submitted for review labels Oct 1, 2019
tpgxyz added a commit to OpenMandrivaAssociation/kernel-release-clang that referenced this issue Oct 4, 2019
@nickdesaulniers
Copy link
Member Author

@nickdesaulniers nickdesaulniers added [FIXED][LINUX] 5.5 This bug was fixed in Linux 5.5 and removed [PATCH] Accepted A submitted patch has been accepted upstream labels Nov 26, 2019
nathanchance pushed a commit to nathanchance/WSL2-Linux-Kernel that referenced this issue Nov 27, 2019
Linking with ld.lld via

$ make LD=ld.lld

produces the warning:

  ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Linking with ld.bfd shows the default entry is 0x1000:

$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly,
instead of depending on the implicit default. The symbol pa_text_start
refers to the start of the .text section, which may not be at 0x1000 if
the preceding sections listed in arch/x86/realmode/rm/realmode.lds.S
were large enough. This matches behavior in arch/x86/boot/setup.ld.

Reported-by: Sedat Dilek <[email protected]>
Suggested-by: Borislav Petkov <[email protected]>
Suggested-by: Peter Smith <[email protected]>
Signed-off-by: Nick Desaulniers <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Ingo Molnar <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Thomas Gleixner <[email protected]>
Cc: x86-ml <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
Link: ClangBuiltLinux/linux#216
(cherry picked from commit 6a181e3)
Signed-off-by: Nathan Chancellor <[email protected]>
@tpimh tpimh removed the low priority This bug is not critical and not a priority label Nov 27, 2019
nathanchance pushed a commit to nathanchance/WSL2-Linux-Kernel that referenced this issue Dec 11, 2019
Linking with ld.lld via

$ make LD=ld.lld

produces the warning:

  ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Linking with ld.bfd shows the default entry is 0x1000:

$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly,
instead of depending on the implicit default. The symbol pa_text_start
refers to the start of the .text section, which may not be at 0x1000 if
the preceding sections listed in arch/x86/realmode/rm/realmode.lds.S
were large enough. This matches behavior in arch/x86/boot/setup.ld.

Reported-by: Sedat Dilek <[email protected]>
Suggested-by: Borislav Petkov <[email protected]>
Suggested-by: Peter Smith <[email protected]>
Signed-off-by: Nick Desaulniers <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Ingo Molnar <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Thomas Gleixner <[email protected]>
Cc: x86-ml <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
Link: ClangBuiltLinux/linux#216
(cherry picked from commit 6a181e3)
Signed-off-by: Nathan Chancellor <[email protected]>
AKoskovich pushed a commit to AKoskovich/WSL that referenced this issue Dec 24, 2019
Linking with ld.lld via

$ make LD=ld.lld

produces the warning:

  ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Linking with ld.bfd shows the default entry is 0x1000:

$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly,
instead of depending on the implicit default. The symbol pa_text_start
refers to the start of the .text section, which may not be at 0x1000 if
the preceding sections listed in arch/x86/realmode/rm/realmode.lds.S
were large enough. This matches behavior in arch/x86/boot/setup.ld.

Reported-by: Sedat Dilek <[email protected]>
Suggested-by: Borislav Petkov <[email protected]>
Suggested-by: Peter Smith <[email protected]>
Signed-off-by: Nick Desaulniers <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Ingo Molnar <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Thomas Gleixner <[email protected]>
Cc: x86-ml <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
Link: ClangBuiltLinux/linux#216
(cherry picked from commit 6a181e333954a26f46596b36f82abd14743570fd)
Signed-off-by: Nathan Chancellor <[email protected]>
AKoskovich pushed a commit to AKoskovich/WSL that referenced this issue Dec 24, 2019
Linking with ld.lld via

$ make LD=ld.lld

produces the warning:

  ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Linking with ld.bfd shows the default entry is 0x1000:

$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly,
instead of depending on the implicit default. The symbol pa_text_start
refers to the start of the .text section, which may not be at 0x1000 if
the preceding sections listed in arch/x86/realmode/rm/realmode.lds.S
were large enough. This matches behavior in arch/x86/boot/setup.ld.

Reported-by: Sedat Dilek <[email protected]>
Suggested-by: Borislav Petkov <[email protected]>
Suggested-by: Peter Smith <[email protected]>
Signed-off-by: Nick Desaulniers <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Ingo Molnar <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Thomas Gleixner <[email protected]>
Cc: x86-ml <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
Link: ClangBuiltLinux/linux#216
(cherry picked from commit 6a181e333954a26f46596b36f82abd14743570fd)
Signed-off-by: Nathan Chancellor <[email protected]>
raphielscape pushed a commit to raphielscape/linux-scape-workstation that referenced this issue Jan 24, 2020
Linking with ld.lld via

$ make LD=ld.lld

produces the warning:

  ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Linking with ld.bfd shows the default entry is 0x1000:

$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly,
instead of depending on the implicit default. The symbol pa_text_start
refers to the start of the .text section, which may not be at 0x1000 if
the preceding sections listed in arch/x86/realmode/rm/realmode.lds.S
were large enough. This matches behavior in arch/x86/boot/setup.ld.

Reported-by: Sedat Dilek <[email protected]>
Suggested-by: Borislav Petkov <[email protected]>
Suggested-by: Peter Smith <[email protected]>
Signed-off-by: Nick Desaulniers <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Ingo Molnar <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Thomas Gleixner <[email protected]>
Cc: x86-ml <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
Link: ClangBuiltLinux/linux#216
(cherry picked from commit 6a181e3)
Signed-off-by: Nathan Chancellor <[email protected]>
@nickdesaulniers
Copy link
Member Author

I suspect this needs to be backported to 5.4, and 4.19 at least.

@nickdesaulniers nickdesaulniers added the Needs Backport Should be backported to either linux-stable tree or latest llvm release branch. label Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[ARCH] x86_64 This bug impacts ARCH=x86_64 [BUG] linux A bug that should be fixed in the mainline kernel. [FIXED][LINUX] 5.5 This bug was fixed in Linux 5.5 Needs Backport Should be backported to either linux-stable tree or latest llvm release branch. [TOOL] lld The issue is relevant to LLD linker
Projects
None yet
Development

No branches or pull requests

5 participants