IT한 것/unix

HP-UX Magic Number

lovian 2009. 2. 2. 14:00

원문: http://hpc.uky.edu/Docs/Prog/performance/chatr.html

Magic Numbers

32비트 모드에서 링커는 프로그램이 어떻게 메모리에 적재되어야할지 결정할 수 있도록 각 실행 프로그로그램에 magic_number를 기록한다. 실행가능 파일의 magic number는 세 종류가 올 수 있다.


In 32-bit mode, the linker records a magic number with each executable program that determines how the program should be loaded. There are three possible values for an executable file's magic number:

Title not available (Magic Numbers )

SHARE_MAGIC
프로그램의 코드는 프로세스들에게 공유된다. ; 그러나 그 프로그램의 데이터는 공유되지 않는다. 프로그램을 실행하는 가장 첫번째 프로세스는 전체 프로그램을 가상 메모리에 적재시켜둔다. 혹시 그 프로그램이 다른 프로세스에 의해서 이미 적재되었다면, 프로세스는 다른 프로세스와 프로그램 코드를 공유한다.

The program's text (code) can be shared by processes; its data cannot be shared. The first process to run the program loads the entire program into virtual memory. If the program is already loaded by another process, then a process shares the program text with the other process.

DEMAND_MAGIC
프로그램의 코드는 공유가능하지만 데이터는 그렇지 않다. 하지만 이 프로그램의 코드는 필요할때(이 프로그램 메모리의 페이지에 접근했을 경우에만)만 적재된다. 이 방식은 전체 프로그램이 적재될 필요가 없기 때문에 프로세스의 기동시간을 단축시켜준다; 그러나 실행할 때마다 성능을 감소시킬 수 있다.

As with SHARE_MAGIC the program's text is shareable but its data is not. However, the program's text is loaded only as needed — that is, only as the pages are accessed. This can improve process startup time since the entire program does not need to be loaded; however, it can degrade performance throughout execution.

EXEC_MAGIC
프로그램의 코드나 데이터는 공유할 수 없다. 다시 말해서, 이 프로그램은 공유할 수 없는 실행파일이다. 보통 이런 종류의 실행파일은 이 프로그램이 차지할 메모리 자원의 요구사항이 커지기 때문에 그다지 선호하지 않는다.

Neither the program's text nor data is shareable. In other words, the program is an unshared executable. Usually, it is not desirable to create such unshared executables because they place greater demands on memory resources.

기본적으로, 링커는 SHARE_MAGIC을 magic number로 가지는 실행가능 파일을 생성한다. 다음은 magic number를 설정하는 링커옵션이다.

By default, the linker creates executables whose magic number is SHARE_MAGIC. The following shows which linker option to use to specifically set the magic number.


32-bit Mode Magic Number Linker Options

To set the magic number to:

Use this option:

SHARE_MAGIC

-n

DEMAND_MAGIC

-q

EXEC_MAGIC

-N


실행가능 파일의 magic number는 chatr 명령으로 변경할 수 있다. 그러나 chatr은 SHAR_MAGIC과 DEMAND_MAGIC만 켜고 끌 수 있다; EXE_MAGIC는 변경을 할 수 없다. 이는 EXEC_MAGIC이 다른 형식인 반면에, SHARE_MAGIC과 DEMAND_MAGIC의 파일 형식이 정확하게 같기 때문이다. magic number에 대한 자세한 사항은 magic(4)를 참조하라.

An executable file's magic number can also be changed using the chatr command (see “Changing a Program's Attributes with chatr(1) ”). However, chatr can only toggle between SHARE_MAGIC and DEMAND_MAGIC; it cannot be used to change from or to EXEC_MAGIC. This is because the file format of SHARE_MAGIC and DEMAND_MAGIC is exactly the same, while EXEC_MAGIC files have a different format. For details on magic numbers, refer to magic(4).

64비트 모드에서 링커는 ELF 객체 파일을 위해 미리 정의된 형식으로 magic number를 설정한다. ELF 객체 파일의 E_TYPE의 값은 그 파일이 어떻게 적재되어야하는지 나타낸다.

In 64-bit mode, the linker sets the magic number to the predefined type for ELF object files (\177ELF). The value of the E_TYPE in the ELF object file specifies how the file should be loaded.