Replace .pushsection directives (#30)

This commit is contained in:
Justine Tunney 2021-01-10 13:30:48 -08:00
parent 28316891e9
commit 04f1d89f84
16 changed files with 171 additions and 10422 deletions

View file

@ -85,10 +85,10 @@ idata.iat.\name:
*/.section .piro.data.sort.iat.2.\name\().3,"awG",\name,comdat
.quad 0
.previous
.pushsection .rodata.str1.1,"aSM",@progbits,1
.section .rodata.str1.1,"aSM",@progbits,1
.Lidata.str.\name:
.asciz "\name\().dll"
.popsection
.previous
.endm
/* clang-format on */

View file

@ -170,7 +170,7 @@ static unsigned char pixels_[3][DYN][DXN];
static unsigned char palette_[3][64][512][3];
static int joy_current_[2], joy_next_[2], joypos_[2];
static int keyframes_ = 20;
static int keyframes_ = 10;
static enum TtyBlocksSelection blocks_ = kTtyBlocksUnicode;
static enum TtyQuantizationAlgorithm quant_ = kTtyQuantTrue;

View file

@ -8,9 +8,9 @@
* Teleports code fragment inside _init().
*/
#define INITIALIZER(PRI, NAME, CODE) \
asm(".pushsection .init." #PRI "." #NAME ",\"ax\",@progbits\n\t" \
asm(".section .init." #PRI "." #NAME ",\"ax\",@progbits\n\t" \
"call\t" #NAME "\n\t" \
".popsection"); \
".previous"); \
textstartup optimizesize void NAME(char *rdi, const char *rsi) { \
CODE; \
asm volatile("" : /* no outputs */ : "D"(rdi), "S"(rsi)); \

View file

@ -65,7 +65,7 @@
#else
#define PFLINK(FMT) FMT
#define SFLINK(FMT) FMT
asm(".pushsection .yoink\n\t"
asm(".section .yoink\n\t"
"nop\tntoa(%rip)\n\t"
"nop\tftoa(%rip)\n\t"
"nop\tkCp437(%rip)\n\t"
@ -77,7 +77,7 @@ asm(".pushsection .yoink\n\t"
"nop\tcalloc(%rip)\n\t"
"nop\tfree_s(%rip)\n\t"
"nop\t__grow(%rip)\n\t"
".popsection");
".previous");
#endif /* __STRICT_ANSI__ */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_FMT_PFLINK_H_ */

View file

@ -776,15 +776,15 @@ typedef uint64_t uintmax_t;
do { \
_Static_assert(!__builtin_types_compatible_p(typeof(SYMBOL), char[]), \
"Please YOINK(symbol), not YOINK(\"symbol\")"); \
asm(".pushsection .yoink\n\t" \
asm(".section .yoink\n\t" \
"nop\t%a0\n\t" \
".popsection" \
".previous" \
: /* no outputs */ \
: "X"(SYMBOL)); \
} while (0)
#define STATIC_YOINK(SYMBOLSTR) \
asm(".pushsection .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.popsection")
asm(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous")
#if !defined(IM_FEELING_NAUGHTY) && !defined(__STRICT_ANSI__)
#define STATIC_YOINK_SOURCE(PATH) STATIC_YOINK(PATH)

View file

@ -16,21 +16,9 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/bits/weaken.h"
#include "libc/calls/internal.h"
#include "libc/dce.h"
#include "libc/log/log.h"
#include "libc/nt/console.h"
#include "libc/nt/enum/consolemodeflags.h"
#include "libc/nt/enum/filetype.h"
#include "libc/nt/enum/version.h"
#include "libc/nt/files.h"
#include "libc/nt/pedef.internal.h"
#include "libc/nt/runtime.h"
#include "libc/nt/struct/teb.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/fileno.h"
/**
* Returns true if ANSI terminal colors are appropriate.

View file

@ -129,9 +129,9 @@
.byte 0x0f,0x1f,0x44,0x00,0x00
#endif
#if defined(__MRECORD_MCOUNT__) && !defined(__MFENTRY__)
.pushsection __mcount_loc,"a",@progbits
.section __mcount_loc,"a",@progbits
.quad 1382b
.popsection
.previous
#endif
#endif
.endm
@ -139,10 +139,10 @@
/ Pushes RVA on stack of linktime mergeable string literal.
/ @see popstr
.macro pushstr text
.pushsection .rodata.str1.1,"aSM",@progbits,1
.section .rodata.str1.1,"aSM",@progbits,1
.Lstr\@: .asciz "\text"
.endobj .Lstr\@
.popsection
.previous
push $.Lstr\@ - IMAGE_BASE_VIRTUAL
.endm
@ -155,12 +155,12 @@
/ Loads address of linktime mergeable string literal into register.
.macro getstr text:req reg64:req reg32 regsz64 regsz32 bias=0
.pushsection .rodata.str1.1,"aSM",@progbits,1
.section .rodata.str1.1,"aSM",@progbits,1
.type .Lstr\@,@object
.Lstr\@: .asciz "\text"
.Lstr\@.size = .-.Lstr\@ - 1
.size .Lstr\@,.-.Lstr\@
.popsection
.previous
plea .Lstr\@,\reg64,\reg32
.ifnb \regsz64
#ifdef __OPTIMIZE_SIZE__
@ -178,12 +178,12 @@
/ TODO(jart): delete
/ Loads address of linktime mergeable string literal into register.
.macro loadstr text:req reg:req regsz bias=0
.pushsection .rodata.str1.1,"aSM",@progbits,1
.section .rodata.str1.1,"aSM",@progbits,1
.type .Lstr\@,@object
.Lstr\@: .asciz "\text"
.Lstr\@.size = .-.Lstr\@ - 1
.size .Lstr\@,.-.Lstr\@
.popsection
.previous
ezlea .Lstr\@,\reg
.ifnb \regsz
#ifdef __OPTIMIZE_SIZE__

View file

@ -253,25 +253,25 @@
.macro .hookable
/ nopl 0x00(%rax,%rax,1)
83457: .byte 0x0f,0x1f,0x44,0x00,0x00
.pushsection __mcount_loc,"a",@progbits
.section __mcount_loc,"a",@progbits
.quad 83457b
.popsection
.previous
.endm
/ Puts initialized data in uninitialized data section.
.macro .bsdata name:req expr:req bnd vis
.pushsection .initbss.300._init_\name,"aw",@nobits
.section .initbss.300._init_\name,"aw",@nobits
\name: .quad 0
.endobj \name,\bnd,\vis
.popsection
.pushsection .initro.300._init_\name,"a",@progbits
.previous
.section .initro.300._init_\name,"a",@progbits
.quad \expr
.popsection
.pushsection .init.300._init_\name,"ax",@progbits
.previous
.section .init.300._init_\name,"ax",@progbits
_init_\name:
movsq
.endfn _init_\name
.popsection
.previous
.endm
/ ICE Breakpoint.
@ -304,14 +304,14 @@ _init_\name:
/ In order for this technique to work with --gc-sections, another
/ module somewhere might want to weakly reference whats yoinked.
.macro yoink symbol:req
.pushsection .yoink
.section .yoink
nop "\symbol"
.popsection
.previous
.endm
.macro .yoink symbol:req
.pushsection .yoink
.section .yoink
nop "\symbol"
.popsection
.previous
.endm
/ Calls Windows function.

View file

@ -1,5 +1,23 @@
#include "libc/nexgen32e/x86feature.h"
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-
│vi: set et ft=asm ts=8 sw=8 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/macros.h"
#include "libc/nexgen32e/x86feature.h"
/ Broadcast byte literal to vector, e.g.
/

View file

@ -1,5 +1,5 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
@ -16,23 +16,58 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/nexgen32e/hascharacter.internal.h"
#include "libc/str/str.h"
#include "libc/macros.h"
/**
* Returns prefix length, consisting of chars not in reject.
* a.k.a. Return index of first byte that's in charset.
*
* @param reject is nul-terminated character set
* @see strspn(), strtok_r()
* @asyncsignalsafe
*/
size_t strcspn(const char *s, const char *reject) {
size_t i;
for (i = 0; s[i]; ++i) {
if (HasCharacter(s[i], reject)) {
break;
}
}
return i;
}
/ Returns prefix length, consisting of chars not in reject.
/ a.k.a. Return index of first byte that's in charset.
/
/ @param rdi is string
/ @param rsi is reject nul-terminated character set
/ @see strspn(), strtok_r()
/ @asyncsignalsafe
strcspn:
push %rbp
mov %rsp,%rbp
sub $16,%rsp
push %rdi
mov %rsi,%rdi
call strlen
pop %rdi
cmp $15,%rax
ja 4f
push %rdi
mov %rax,%rdx
pxor %xmm0,%xmm0
lea -16(%rbp),%rdi
movdqa %xmm0,(%rdi)
call MemCpy
movdqa (%rdi),%xmm1
pop %rdi
or $-1,%rax
0: inc %rax
movzbl (%rdi,%rax),%ecx
movd %ecx,%xmm0
punpcklbw %xmm0,%xmm0
punpcklwd %xmm0,%xmm0
pshufd $0,%xmm0,%xmm0
pcmpeqb %xmm1,%xmm0
pmovmskb %xmm0,%ecx
test %ecx,%ecx
jz 0b
9: leave
ret
1: cmp %ch,%cl
je 9b
inc %edx
2: mov (%rsi,%rdx),%ch
test %ch,%ch
jne 1b
inc %rax
3: mov (%rdi,%rax),%cl
test %cl,%cl
je 9b
xor %edx,%edx
jmp 2b
4: xor %eax,%eax
jmp 3b
.endfn strcspn,globl

View file

@ -2,18 +2,18 @@
#define COSMOPOLITAN_LIBC_NEXGEN32E_TRAMPOLINE_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#define TRAMPOLINE(FUNCTION, THUNK) \
({ \
typeof(FUNCTION) *Tramp; \
asm(".pushsection .text.trampoline\n" \
"183:\n\t" \
"mov\t%1,%%eax\n\t" \
"jmp\t" #THUNK "\n\t" \
".popsection\n\t" \
"mov\t$183b,%k0" \
: "=r"(Tramp) \
: "i"(FUNCTION)); \
Tramp; \
#define TRAMPOLINE(FUNCTION, THUNK) \
({ \
typeof(FUNCTION) *Tramp; \
asm(".section .text.trampoline\n" \
"183:\n\t" \
"mov\t%1,%%eax\n\t" \
"jmp\t" #THUNK "\n\t" \
".previous\n\t" \
"mov\t$183b,%k0" \
: "=r"(Tramp) \
: "i"(FUNCTION)); \
Tramp; \
})
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,49 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
TEST(strcspn, test) {
EXPECT_EQ(0, strcspn("abcdefg", "ae"));
EXPECT_EQ(0, strcspn("abcdefg", "aeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"));
EXPECT_EQ(4, strcspn("abcdefg", "ze"));
EXPECT_EQ(4, strcspn("abcdefg", "zeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"));
EXPECT_EQ(5, strcspn("abcdfzg", "ze"));
EXPECT_EQ(5, strcspn("abcdfzg", "zeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"));
EXPECT_EQ(7, strcspn("abcdEfg", "ze"));
EXPECT_EQ(7, strcspn("abcdEfg", "zeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"));
EXPECT_EQ(31, strcspn("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOp", "abcdefghijklmnp"));
EXPECT_EQ(31, strcspn("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOp",
"abcdefghijklmnpabcdefghijklmnp"));
}
BENCH(strcspn, bench) {
EZBENCH2("strcspn", donothing,
EXPROPRIATE(
strcspn("pABCDEFGHIJKLMNOPABCDEFGHIJKLMNO", "abcdefghijklmnp")));
EZBENCH2("strcspn", donothing,
EXPROPRIATE(
strcspn("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOp", "abcdefghijklmnp")));
EZBENCH2(
"strcspn", donothing,
EXPROPRIATE(strcspn(
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOABCDEFGHIJKLMNOPABCDEFGHIJKLMNOp",
"abcdefghijklmnp")));
}

View file

@ -24,6 +24,7 @@ o/$(MODE)/test/libc/release/smoke.com: \
-fno-pie \
-nostdlib \
-nostdinc \
-mno-red-zone \
-Wl,--gc-sections \
-Wl,--oformat=binary \
-Wl,-z,max-page-size=0x1000 \

View file

@ -1,7 +1,7 @@
asm(".pushsection .start,\"ax\",@progbits\n\t"
asm(".section .start,\"ax\",@progbits\n\t"
".globl\t_start\n"
"_start:\n\t"
"jmp\t1f\n1:\t"
"call\tmain\n\t"
"nop\n\t"
".popsection");
".previous");

View file

@ -23,9 +23,9 @@
.Lrows = 0 # w/ 2 cols
.macro .tab sym:req str
.pushsection .rodata.str1.1,"aSM",@progbits,1
.section .rodata.str1.1,"aSM",@progbits,1
.L\@: .asciz "\str"
.popsection
.previous
.long RVA(\sym)
.long RVA(.L\@)
.Lrows = .Lrows + 1