tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Linking with cosmopolitan: Invalid relocation entry


From: Domingo Alvarez Duarte
Subject: Re: [Tinycc-devel] Linking with cosmopolitan: Invalid relocation entry
Date: Wed, 12 Oct 2022 18:13:08 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2

Looking at it in more depth and comparing with the gcc command line I can see that it only work with gcc using a custom link script.

=====

# run gcc compiler in freestanding mode
gcc -fno-pie -no-pie -nostdlib -nostdinc \
  -o hello-gcc.com.dbg hello-tcc.c  \
  -Wl,-T,ape.lds \
   crt.o ape-no-modify-self.o cosmopolitan.a

=====

ape.lds

=====

ENTRY(_start)
PHDRS {
  Head 1 FLAGS(1|4);
  Rom 1 FLAGS(1|4);
  Ram 1 FLAGS(2|4);
  Tls 7 FLAGS(2|4);
  Bss 1 FLAGS(2|4);
  stack 0x6474e551 FLAGS(2|4);
}
SECTIONS {
  .head SEGMENT_START("text-segment", 0x400000) : AT(0x2000) {
    HIDDEN(_base = .);
    KEEP(*(.head))
    KEEP(*(.apesh))
    KEEP(*(.head2))
    KEEP(*(.text.head))
    . = ALIGN(8);
    HIDDEN(ape_phdrs = .);
    KEEP(*(.elf.phdrs))
    HIDDEN(ape_phdrs_end = .);
    . = ALIGN(8);
    HIDDEN(ape_note = .);
    KEEP(*(.note.openbsd.ident))
    KEEP(*(.note.netbsd.ident))
    HIDDEN(ape_note_end = .);
    KEEP(*(.pe.header))
    HIDDEN(ape_pe_sections = .);
    KEEP(*(.pe.sections))
    HIDDEN(ape_pe_sections_end = .);
    KEEP(*(.macho))
    . = ALIGN(8);
    HIDDEN(ape_macho_end = .);
    KEEP(*(.ape.pad.head))
    . = ALIGN(((255 & 4) == 4) || ((255 & 2) == 2) ? 0x1000 : 16);
    HIDDEN(_ehead = .);
  } :Head
  .text . : {
    BYTE(0x90)
    *(.text.real)
    KEEP(*(SORT_BY_NAME(.sort.text.real.*)))
    KEEP(*(.ape.loader))
    HIDDEN(_ereal = .);
    . += 1;
    *(.start)
    KEEP(*(.initprologue))
    KEEP(*(SORT_BY_NAME(.init.*)))
    KEEP(*(.init))
    KEEP(*(.initepilogue))
    KEEP(*(.pltprologue))
    *(.plt)
    KEEP(*(.pltepilogue))
    KEEP(*(.pltgotprologue))
    *(.plt.got)
    KEEP(*(.pltgotepilogue))
    *(.text.startup .text.startup.*)
    *(.text.exit .text.exit.*)
    *(.text.unlikely .text.*_unlikely .text.unlikely.*)
    *(SORT_BY_ALIGNMENT(.text.antiquity))
    *(SORT_BY_ALIGNMENT(.text.antiquity.*))
    KEEP(*(.textwindowsprologue))
    *(.text.windows)
    KEEP(*(.textwindowsepilogue))
    *(SORT_BY_ALIGNMENT(.text.modernity))
    *(SORT_BY_ALIGNMENT(.text.modernity.*))
    *(SORT_BY_ALIGNMENT(.text.hot))
    *(SORT_BY_ALIGNMENT(.text.hot.*))
    KEEP(*(.keep.text))
    *(.text .stub .text.*)
    KEEP(*(SORT_BY_NAME(.sort.text.*)))

...

ASSERT((!DEFINED(ape_grub) ? 1 : ((ape_grub) - (0x400000)) < 8192),
       "grub stub needs to be in first 8kb of image");
ASSERT(DEFINED(_start) || DEFINED(_start16),
       "please link a _start() or _start16() entrypoint");
ASSERT(!DEFINED(_start16) || ((_end) - (0x400000 - 0x2000)) < 65536,
       "ape won't support non-tiny real mode programs");
ASSERT((!((ape_stack_memsz) & ((ape_stack_memsz)-1))),
       "ape_stack_memsz must be a two power");
ASSERT(ape_stack_vaddr % ape_stack_memsz == 0,
       "ape_stack_vaddr must have ape_stack_memsz alignment; try using STATIC_STACK_ADDR(0x700000040000 - ape_stack_memsz);");
ASSERT(ALIGNOF(.tdata) <= 64 && ALIGNOF(.tbss) <= 64,
       "_Thread_local _Alignof can't exceed TLS_ALIGNMENT");

=====

On 12/10/22 17:44, Domingo Alvarez Duarte wrote:
Hello !

I'm trying to use tcc to build a test program using cosmopolitan libc https://github.com/jart/cosmopolitan and I'm getting this error : "cosmopolitan.a: error: Invalid relocation entry [ 2] '.rela.text' @ 0000000c".

Here is the C program:

=====

typedef short __CHAR16_TYPE__;
typedef int __CHAR32_TYPE__;
typedef signed char __INT8_TYPE__;
typedef unsigned char __UINT8_TYPE__;
typedef short __INT16_TYPE__ ;
typedef unsigned short __UINT16_TYPE__;
typedef unsigned int __UINT32_TYPE__;
typedef unsigned long __UINT64_TYPE__;
typedef long long __INTMAX_TYPE__;
typedef unsigned long long __UINTMAX_TYPE__;

typedef signed char __INT_LEAST8_TYPE__;
typedef unsigned char __UINT_LEAST8_TYPE__;
typedef short __INT_LEAST16_TYPE__;
typedef unsigned short __UINT_LEAST16_TYPE__;
typedef int __INT_LEAST32_TYPE__;
typedef unsigned int __UINT_LEAST32_TYPE__;
typedef long __INT_LEAST64_TYPE__;
typedef unsigned long __UINT_LEAST64_TYPE__;

typedef signed char __INT_FAST8_TYPE__;
typedef unsigned char __UINT_FAST8_TYPE__;
typedef short __INT_FAST16_TYPE__;
typedef unsigned short __UINT_FAST16_TYPE__;
typedef int __INT_FAST32_TYPE__;
typedef unsigned int __UINT_FAST32_TYPE__;
typedef long __INT_FAST64_TYPE__;
typedef unsigned long __UINT_FAST64_TYPE__;

#define __STRICT_ANSI__

#include "cosmopolitan.h"
int main(int argc, char *argv) {
    printf("hello world\n");
    return 0;
}

=====

And here is the command line:

=====

# run gcc compiler in freestanding mode
tinycc-env tcc -nostdlib -nostdinc \
  -o hello-tcc.com.dbg hello-tcc.c  \
   crt.o ape-no-modify-self.o cosmopolitan.a
#objcopy -S -O binary hello-tcc.com.dbg hello-tcc.com

# NOTE: scp it to windows/mac/etc. *before* you run it!
# ~40kb static binary (can be ~16kb w/ MODE=tiny)
#./ape.elf ./hello-tcc.com

=====

Here is the folder content:

=====

total 54520
-rwxr-xr-x 1 mingo mingo    22192 oct 11 06:07 ape-copy-self.o
-rwxr-xr-x 1 mingo mingo   146720 oct 11 06:07 ape.lds
-rwxr-xr-x 1 mingo mingo    31000 oct 11 06:07 ape-no-modify-self.o
-rwxr-xr-x 1 mingo mingo    22192 oct 11 06:07 ape.o
-rwxr-xr-x 1 mingo mingo 54084380 oct 11 06:07 cosmopolitan.a
-rwxr-xr-x 1 mingo mingo  1472975 oct 11 06:08 cosmopolitan.h
-rwxr-xr-x 1 mingo mingo     3608 oct 11 06:07 crt.o
-rw-rw-r-- 1 mingo mingo    12620 oct 12 17:16 gcc-macros.h
-rwxrwxr-x 1 mingo mingo     3648 oct 12 17:23 hello-tcc
-rw-rw-r-- 1 mingo mingo     1135 oct 12 17:22 hello-tcc.c
-rwxrw-r-- 1 mingo mingo      348 oct 12 17:33 mk-hello-tcc.sh
-rw-rw-r-- 1 mingo mingo       66 oct 12 17:16 mk-it-tcc.sh

=====

Can someone with more experience shed some light here ?

Cheers !




reply via email to

[Prev in Thread] Current Thread [Next in Thread]