mirror of
git://repo.or.cz/tinycc.git
synced 2026-11-05 05:36:35 +08:00
The traditional boundary symbols were recorded against the canonical .text, .data and .bss sections before dynamic binding and final layout. Separately named allocatable sections and copy-relocated data could therefore fall outside the advertised ranges. Track definitions synthesized by the linker and finalize them from the ordered loadable sections. Refresh both regular and dynamic symbol tables, and give the plain etext, edata and end names PROVIDE semantics on every ELF target while preserving user definitions. Cover archive references, overrides, copy relocations and independently named text/data/bss sections. Reported-by: Richard Wheeler <18647491+PythonWillRule@users.noreply.github.com>
32 lines
1.0 KiB
C
32 lines
1.0 KiB
C
#include <stdio.h>
|
|
|
|
extern void linker_test_text(void);
|
|
extern unsigned char linker_test_data[23];
|
|
extern unsigned char linker_test_bss[257];
|
|
extern char etext[], _etext[];
|
|
extern char edata[], _edata[];
|
|
extern char end[], _end[];
|
|
|
|
int main(void)
|
|
{
|
|
unsigned long text_addr = (unsigned long)linker_test_text;
|
|
unsigned long data_end = (unsigned long)(linker_test_data
|
|
+ sizeof linker_test_data);
|
|
unsigned long bss_end = (unsigned long)(linker_test_bss
|
|
+ sizeof linker_test_bss);
|
|
int errors = 0;
|
|
|
|
linker_test_data[22] = 42;
|
|
linker_test_bss[256] = 42;
|
|
errors += etext != _etext;
|
|
errors += edata != _edata;
|
|
errors += end != _end;
|
|
errors += (unsigned long)etext <= text_addr;
|
|
errors += (unsigned long)edata < data_end;
|
|
errors += (unsigned long)end < bss_end;
|
|
errors += linker_test_data[22] != 42;
|
|
errors += linker_test_bss[256] != 42;
|
|
printf("linker boundary errors: %d\n", errors);
|
|
return errors;
|
|
}
|