|
| 1 | +#---EntryCmdPrecedence.test-------------- Executable,LS ----------------------# |
| 2 | +#BEGIN_COMMENT |
| 3 | +# Tests GNU ld entry point precedence rules: |
| 4 | +# Case 1: Last ENTRY() in a single script wins over earlier ENTRY() commands. |
| 5 | +# Case 2: Command-line -e always overrides any script ENTRY(). |
| 6 | +# Case 3: Last -e on command line wins over earlier -e. |
| 7 | +# Case 4: -e with a raw address overrides script ENTRY(). |
| 8 | +# Case 5: Across multiple -T scripts, the last ENTRY() activated wins. |
| 9 | +# Case 6: -e overrides script ENTRY() regardless of command-line order |
| 10 | +# (i.e. -e placed before -T still wins). |
| 11 | +# |
| 12 | +# Input scripts fix symbol addresses so entry points can be verified with |
| 13 | +# literal address checks (same style as EntryCmd.test): |
| 14 | +# two_entries.t : bar=0x1000, foo=0x2000 |
| 15 | +# script.t : foo=0x1000, bar=0x2000 |
| 16 | +# entry_foo.t : bar=0x1000, foo=0x2000 (SECTIONS; entry_bar.t is ENTRY only) |
| 17 | +#END_COMMENT |
| 18 | +#START_TEST |
| 19 | +RUN: %clang %clangopts -c %p/Inputs/1.c -o %t1.o -ffunction-sections |
| 20 | + |
| 21 | +# Case 1: ENTRY(bar) then ENTRY(foo) in one script -- foo must win (last wins). |
| 22 | +RUN: %link %linkopts %t1.o -T %p/Inputs/two_entries.t -o %t.lastwins.out |
| 23 | +RUN: %readelf -h %t.lastwins.out | %filecheck %s --check-prefix=LASTWINS |
| 24 | +#LASTWINS: Entry point address: 0x2000 |
| 25 | + |
| 26 | +# Case 2: -e bar overrides the script ENTRY(foo) -- command line always wins. |
| 27 | +RUN: %link %linkopts %t1.o -T %p/Inputs/two_entries.t -e bar -o %t.cmdline.out |
| 28 | +RUN: %readelf -h %t.cmdline.out | %filecheck %s --check-prefix=CMDLINE |
| 29 | +#CMDLINE: Entry point address: 0x1000 |
| 30 | + |
| 31 | +# Case 3: -e foo -e bar -- bar must win (last -e wins). |
| 32 | +RUN: %link %linkopts %t1.o -T %p/Inputs/script.t -e foo -e bar -o %t.lastcmd.out |
| 33 | +RUN: %readelf -h %t.lastcmd.out | %filecheck %s --check-prefix=LASTCMD |
| 34 | +#LASTCMD: Entry point address: 0x2000 |
| 35 | + |
| 36 | +# Case 4: -e 0 overrides script ENTRY(foo) -- entry must be 0x0. |
| 37 | +RUN: %link %linkopts %t1.o -T %p/Inputs/script.t -e 0 -o %t.rawaddr.out |
| 38 | +RUN: %readelf -h %t.rawaddr.out | %filecheck %s --check-prefix=RAWADDR |
| 39 | +#RAWADDR: Entry point address: 0x0 |
| 40 | + |
| 41 | +# Case 5: Two separate scripts, ENTRY(bar) then ENTRY(foo) -- last script wins. |
| 42 | +RUN: %link %linkopts %t1.o -T %p/Inputs/entry_bar.t -T %p/Inputs/entry_foo.t -o %t.crossscript.out |
| 43 | +RUN: %readelf -h %t.crossscript.out | %filecheck %s --check-prefix=CROSSSCRIPT |
| 44 | +#CROSSSCRIPT: Entry point address: 0x2000 |
| 45 | + |
| 46 | +# Case 6: -e bar placed BEFORE -T -- command line still wins over script ENTRY(foo). |
| 47 | +RUN: %link %linkopts %t1.o -e bar -T %p/Inputs/two_entries.t -o %t.eorder.out |
| 48 | +RUN: %readelf -h %t.eorder.out | %filecheck %s --check-prefix=EORDER |
| 49 | +#EORDER: Entry point address: 0x1000 |
| 50 | +#END_TEST |
0 commit comments