0
1

リンカ・ローダ

各社のリンカ、ローダ、libralian、locator、boot loaderなどの機能を調べる上で、
「リンカ・ローダ実践開発テクニック」 坂井弘亮
は、手がかりをつかめるかもしれない。

リンカ・ローダ実践開発テクニック―実行ファイルを作成するために必須の技術-COMPUTER-TECHNOLOGY-坂井-弘亮
https://www.amazon.co.jp//dp/4789838072/
https://bookmeter.com/books/630946

参考文献にあるLinkers & Loadersは斜め読みしただけで、自分ではこういう道具は作らないだろうと勝手に思っていた。本書では簡易リンカの作成と、道具の作り方まで有るのがすごい。「setjmp()とlongjmp()」というコラムが1頁に入りきらず4頁になっているのに、節にしていないところも興味深い。

<この項は書きかけです。順次追記します。>
This article is not completed. I will add some words in order.

content

content
https://shop.cqpub.co.jp/hanbai/books/38/38071.html

ardump.c リンカ・ローダ実践開発テクニック 坂井弘亮(1) coding(89)
https://qiita.com/kaizen_nagoya/items/2a7bf3050ee6ac662272

binary.c リンカ・ローダ実践開発テクニック 坂井弘亮(2) coding(90)
https://qiita.com/kaizen_nagoya/items/23b985cefc5338677812

combine.c リンカ・ローダ実践開発テクニック 坂井弘亮(3) coding(91)
https://qiita.com/kaizen_nagoya/items/59161e3274270cfd2009

const.c, リンカ・ローダ実践開発テクニック 坂井弘亮(4) coding(92) error(123) docker(174)
https://qiita.com/kaizen_nagoya/items/6f74dbf637a91685d0d1

constructor.c リンカ・ローダ実践開発テクニック 坂井弘亮(5) coding(93)
https://qiita.com/kaizen_nagoya/items/37e14a0943907b6f836f

continue.c リンカ・ローダ実践開発テクニック 坂井弘亮(6) coding(95)
https://qiita.com/kaizen_nagoya/items/e124223fd49db6d9e7a2

down.c リンカ・ローダ実践開発テクニック 坂井弘亮(7) coding(96)
https://qiita.com/kaizen_nagoya/items/866449f129cc8ce4dee7

ctors.c リンカ・ローダ実践開発テクニック 坂井弘亮(8) coding(97)
https://qiita.com/kaizen_nagoya/items/135524de5f8fea10e90f

duplicate.c リンカ・ローダ実践開発テクニック 坂井弘亮(9) coding(123)
https://qiita.com/kaizen_nagoya/items/2339c517f223e556bf67

edata.c リンカ・ローダ実践開発テクニック 坂井弘亮(10) coding(124)
https://qiita.com/kaizen_nagoya/items/bbfe0d6a3c5375026c64

elfread.c リンカ・ローダ実践開発テクニック 坂井弘亮(11) coding(125)
https://qiita.com/kaizen_nagoya/items/600c4a1133dc08da215e

edata.c リンカ・ローダ実践開発テクニック 坂井弘亮(12) coding(126)
https://qiita.com/kaizen_nagoya/items/b6eff6b348d7cf5f257c

hello.c リンカ・ローダ実践開発テクニック 坂井弘亮(13) coding(127)
https://qiita.com/kaizen_nagoya/items/4af05d017d73ebe789d5

inicialize.c リンカ・ローダ実践開発テクニック 坂井弘亮(14) coding(128)
https://qiita.com/kaizen_nagoya/items/4feeb9ef85bfc28fd821

layer.c リンカ・ローダ実践開発テクニック 坂井弘亮(15) coding(129)
https://qiita.com/kaizen_nagoya/items/90bb95f9e538e66d2dbf

ordermain.c リンカ・ローダ実践開発テクニック 坂井弘亮(16) coding(130)
https://qiita.com/kaizen_nagoya/items/446a6768a0abdd13c8b5

pointer.c リンカ・ローダ実践開発テクニック 坂井弘亮(17) coding(131)
https://qiita.com/kaizen_nagoya/items/68cae98797c2e6018499

rasm.c リンカ・ローダ実践開発テクニック 坂井弘亮(18) coding(132)
https://qiita.com/kaizen_nagoya/items/6c3ac31457551e788163

section.c リンカ・ローダ実践開発テクニック 坂井弘亮(19) coding(133)
https://qiita.com/kaizen_nagoya/items/00aadb9a9c0a222ebce2

setjmp.c リンカ・ローダ実践開発テクニック 坂井弘亮(20) coding(134)
https://qiita.com/kaizen_nagoya/items/648200e728c982e79819

sample.c リンカ・ローダ実践開発テクニック 坂井弘亮(21) coding(135)
https://qiita.com/kaizen_nagoya/items/360d99ed47ddc4780bf2

N3220 Information technology — Programming languages — C N3220 working draft
https://www.open-std.org/JTC1/SC22/WG14/www/docs/n3220.pdf
N3219 Information technology — Programming languages — C ISO/IEC 9899:2023 DIS Draft
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3219.pdf

プログラムには少し手を入れています。最近の型宣言に厳しい感じで。

estjmp.c
 <stdio.h>
#include <setjmp.h>

static jmp_buf buf;

int func(void)
{
  printf("func()\n");
  _longjmp(buf, 1);
  printf("return from _longjmp()\n");
}

int main(void)
{
  int ret;

  ret = _setjmp(buf);
  printf("return from _setjmp()\n");
  if (ret == 0) {
    printf("return with zero.\n");
    func();
    printf("return from func()\n");
  } else {
    /* _longjmp() からの復旧 */
    printf("ret = %d\n", ret);
  }
  printf("exit.\n");
  exit (0);
}

setjmp

C N3219 7 Library 7.13 Non-localjumps
7.13.1 Save calling environment 7.13.1.1 The setjmp macro

Synopsis

#include <setjmp.h>
int setjmp(jmp_buf env);

Description

The setjmp macro saves its calling environment in its jmp_buf argument for later use by the longjmp function.

Returns

If the return is from a direct invocation, the setjmp macro returns the value zero. If the return is from a call to the longjmp function, the setjmp macro returns a nonzero value.

Environmental limits

An invocation of the setjmp macro shall appear only in one of the following contexts:
— the entire controlling expression of a selection or iteration statement;
— one operand of a relational or equality operator with the other operand an integer constant expression, with the resulting expression being the entire controlling expression of a selection or iteration statement;
— the operand of a unary ! operator with the resulting expression being the entire controlling expression of a selection or iteration statement; or
— the entire expression of an expression statement (possibly cast to void).
If the invocation appears in any other context, the behavior is undefined.

longjmp

C N3219 7 Library 7.13 Non-localjumps
7.13.2 Restore calling environment 7.13.2.1 The longjmp function

Synopsis

#include <setjmp.h>
[[noreturn]] void longjmp(jmp_buf env, int val);

Description

The longjmp function restores the environment saved by the most recent invocation of the setjmp macro in the same invocation of the program with the corresponding jmp_buf argument. If there has been no such invocation, or if the invocation was from another thread of execution, or if the function containing the invocation of the setjmp macro has terminated execution290) in the interim, or if the invocation of the setjmp macro was within the scope of an identifier with variably modified type and execution has left that scope in the interim, the behavior is undefined.
All accessible objects have values, and all other components of the abstract machine291) have state, as of the time the longjmp function was called, except that the representation of objects of automatic storage duration that are local to the function containing the invocation of the corresponding setjmp macro that do not have volatile-qualified type and have been changed between the setjmp invocation and longjmp call is indeterminate.

Returns

After longjmp is completed, thread execution continues as if the corresponding invocation of the setjmp macro had just returned the value specified by val. The longjmp function cannot cause the setjmp macro to return the value 0; if val is 0, the setjmp macro returns the value 1.
EXAMPLE The longjmp function that returns control back to the point of the setjmp invocation can cause memory associated with a variable length array object to be squandered.

#include <setjmp.h> jmp_buf buf;
void g(int n);
void h(int n);
int n = 6; void f(void)
{
}
int x[n]; setjmp(buf); g(n);
// valid: f is not terminated
// a may remain allocated
// b may remain allocated // can cause memory loss
void g(int n) {
int a[n];
h(n); }
void h(int n) {
}
int b[n]; longjmp(buf, 2);

290)For example, by executing a return statement or because another longjmp call has caused a transfer to a setjmp invocation in a function earlier in the set of nested calls.
291)This includes, but is not limited to, the floating-point environment and the state of open files.

関連資料

' @kazuo_reve 私が効果を確認した「小川メソッド」
https://qiita.com/kazuo_reve/items/a3ea1d9171deeccc04da

' @kazuo_reve 新人の方によく展開している有益な情報
https://qiita.com/kazuo_reve/items/d1a3f0ee48e24bba38f1

' @kazuo_reve Vモデルについて勘違いしていたと思ったこと
https://qiita.com/kazuo_reve/items/46fddb094563bd9b2e1e

自己記事一覧

プログラマが知っていると良い「公序良俗」
https://qiita.com/kaizen_nagoya/items/9fe7c0dfac2fbd77a945

逆も真:社会人が最初に確かめるとよいこと。OSEK(69)、Ethernet(59)
https://qiita.com/kaizen_nagoya/items/39afe4a728a31b903ddc

「何を」よりも「誰を」。10年後のために今見習いたい人たち
https://qiita.com/kaizen_nagoya/items/8045978b16eb49d572b2

Qiitaの記事に3段階または5段階で到達するための方法
https://qiita.com/kaizen_nagoya/items/6e9298296852325adc5e

物理記事 上位100
https://qiita.com/kaizen_nagoya/items/66e90fe31fbe3facc6ff

量子(0) 計算機, 量子力学
https://qiita.com/kaizen_nagoya/items/1cd954cb0eed92879fd4

数学関連記事100
https://qiita.com/kaizen_nagoya/items/d8dadb49a6397e854c6d

統計(0)一覧
https://qiita.com/kaizen_nagoya/items/80d3b221807e53e88aba

図(0) state, sequence and timing. UML and お絵描き
https://qiita.com/kaizen_nagoya/items/60440a882146aeee9e8f

品質一覧
https://qiita.com/kaizen_nagoya/items/2b99b8e9db6d94b2e971

言語・文学記事 100
https://qiita.com/kaizen_nagoya/items/42d58d5ef7fb53c407d6

医工連携関連記事一覧
https://qiita.com/kaizen_nagoya/items/6ab51c12ba51bc260a82

自動車 記事 100
https://qiita.com/kaizen_nagoya/items/f7f0b9ab36569ad409c5

通信記事100
https://qiita.com/kaizen_nagoya/items/1d67de5e1cd207b05ef7

日本語(0)一欄
https://qiita.com/kaizen_nagoya/items/7498dcfa3a9ba7fd1e68

英語(0) 一覧
https://qiita.com/kaizen_nagoya/items/680e3f5cbf9430486c7d

転職(0)一覧
https://qiita.com/kaizen_nagoya/items/f77520d378d33451d6fe

仮説(0)一覧(目標100現在40)
https://qiita.com/kaizen_nagoya/items/f000506fe1837b3590df

音楽 一覧(0)
https://qiita.com/kaizen_nagoya/items/b6e5f42bbfe3bbe40f5d

@kazuo_reve 新人の方によく展開している有益な情報」確認一覧
https://qiita.com/kaizen_nagoya/items/b9380888d1e5a042646b

Qiita(0)Qiita関連記事一覧(自分)
https://qiita.com/kaizen_nagoya/items/58db5fbf036b28e9dfa6

鉄道(0)鉄道のシステム考察はてっちゃんがてつだってくれる
https://qiita.com/kaizen_nagoya/items/26bda595f341a27901a0

安全(0)安全工学シンポジウムに向けて: 21
https://qiita.com/kaizen_nagoya/items/c5d78f3def8195cb2409

一覧の一覧( The directory of directories of mine.) Qiita(100)
https://qiita.com/kaizen_nagoya/items/7eb0e006543886138f39

Ethernet 記事一覧 Ethernet(0)
https://qiita.com/kaizen_nagoya/items/88d35e99f74aefc98794

Wireshark 一覧 wireshark(0)、Ethernet(48)
https://qiita.com/kaizen_nagoya/items/fbed841f61875c4731d0

線網(Wi-Fi)空中線(antenna)(0) 記事一覧(118/300目標)
https://qiita.com/kaizen_nagoya/items/5e5464ac2b24bd4cd001

OSEK OS設計の基礎 OSEK(100)
https://qiita.com/kaizen_nagoya/items/7528a22a14242d2d58a3

Error一覧 error(0)
https://qiita.com/kaizen_nagoya/items/48b6cbc8d68eae2c42b8

++ Support(0) 
https://qiita.com/kaizen_nagoya/items/8720d26f762369a80514

Coding(0) Rules, C, Secure, MISRA and so on
https://qiita.com/kaizen_nagoya/items/400725644a8a0e90fbb0

coding (101) 一覧を作成し始めた。omake:最近のQiitaで表示しない5つの事象
https://qiita.com/kaizen_nagoya/items/20667f09f19598aedb68

プログラマによる、プログラマのための、統計(0)と確率のプログラミングとその後
https://qiita.com/kaizen_nagoya/items/6e9897eb641268766909

なぜdockerで機械学習するか 書籍・ソース一覧作成中 (目標100)
https://qiita.com/kaizen_nagoya/items/ddd12477544bf5ba85e2

言語処理100本ノックをdockerで。python覚えるのに最適。:10+12
https://qiita.com/kaizen_nagoya/items/7e7eb7c543e0c18438c4

プログラムちょい替え(0)一覧:4件
https://qiita.com/kaizen_nagoya/items/296d87ef4bfd516bc394

Python(0)記事をまとめたい。
https://qiita.com/kaizen_nagoya/items/088c57d70ab6904ebb53

官公庁・学校・公的団体(NPOを含む)システムの課題、官(0)
https://qiita.com/kaizen_nagoya/items/04ee6eaf7ec13d3af4c3

「はじめての」シリーズ  ベクタージャパン 
https://qiita.com/kaizen_nagoya/items/2e41634f6e21a3cf74eb

AUTOSAR(0)Qiita記事一覧, OSEK(75)
https://qiita.com/kaizen_nagoya/items/89c07961b59a8754c869

プログラマが知っていると良い「公序良俗」
https://qiita.com/kaizen_nagoya/items/9fe7c0dfac2fbd77a945

LaTeX(0) 一覧 
https://qiita.com/kaizen_nagoya/items/e3f7dafacab58c499792

自動制御、制御工学一覧(0)
https://qiita.com/kaizen_nagoya/items/7767a4e19a6ae1479e6b

Rust(0) 一覧 
https://qiita.com/kaizen_nagoya/items/5e8bb080ba6ca0281927

100以上いいねをいただいた記事16選
https://qiita.com/kaizen_nagoya/items/f8d958d9084ffbd15d2a

小川清最終講義、最終講義(再)計画, Ethernet(100) 英語(100) 安全(100)
https://qiita.com/kaizen_nagoya/items/e2df642e3951e35e6a53

<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>
This article is an individual impression based on my individual experience. It has nothing to do with the organization or business to which I currently belong.

文書履歴(document history)

ver. 0.01 初稿  20240714

最後までおよみいただきありがとう4ざいました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1